title 'Product Function : OLS';

options ls=78 ps=63;

data kobdug;
 input OBS T YEAR  MH85  K85  GDP GDP85  GNP  GNP85;
 LNMH85 = LOG(MH85);
 LNK85  = LOG(K85);
 LNGD85 = LOG(GDP85);
 LNYL = LOG( GDP85 / MH85 );
 LNKL = LOG( K85 / MH85 );

 drop OBS GNP GNP85;

 cards;
   1    1    70     93.157    30.121   171661    53.578   171293    53.274
   2    2    71     92.740    34.518   178981    55.862   178737    55.589
   3    3    72     92.307    38.939   193699    60.456   193708    60.245
   4    4    73     93.764    43.317   208470    65.066   208515    64.850
   5    5    74     90.021    47.553   207183    64.664   206806    64.319
   6    6    75     88.015    51.801   213108    66.514   212876    66.207
   7    7    76     90.155    55.922   222084    69.315   221870    69.004
   8    8    77     91.435    59.892   232550    72.582   232430    72.288
   9    9    78     92.873    63.667   243873    76.116   243953    75.872
  10   10    79     94.577    67.687   257372    80.329   257696    80.146
  11   11    80     95.308    72.227   266722    83.247   266634    82.926
  12   12    81     95.739    76.976   276268    86.227   275680    85.739
  13   13    82     96.493    81.723   285002    88.953   285070    88.660
  14   14    83     98.173    86.436   292701    91.356   293023    91.133
  15   15    84     99.606    91.561   305187    95.253   305697    95.075
  16   16    85    100.000   100.000   320397   100.000   321533   100.000
  17   17    86    100.531   109.033   328816   102.628   330022   102.640
  18   18    87    101.894   116.798   342315   106.841   344333   107.091
  19   19    88    103.576   124.775   363567   113.474   365823   113.775
  20   20    89    104.469   132.909   380709   118.824   383447   119.256
  21   21    90    104.682   142.579   399043   124.546   401812   124.968
  22   22    91    104.812   153.228   415196   129.588   418145   130.047
  23   23    92    103.642   164.095   420454   131.229   424314   131.966
;
run;

filename GSASFILE '~/shizu/graph.ps';
goptions GACCESS = GSASFILE
         device = xcolor
         rotate = landscape
         gsfmode = replace;

/**************************************************/
/******************* PART 1 ***********************/
/**************************************************/

/******************* trend *************************/

title 'trend';

proc reg;
 model LNGD85 = T;
 model LNMH85 = T;
 model LNK85  = T;
run;

/******** OLS:LNGD85 = C+ a LNMH85 +b LNK85 *****************/
proc reg data=kobdug;
  model LNGD85 = LNMH85 LNK85 / p r dw;
run;

/******** OLS:LNGD85 = C+ a LNMH85 + b LNK85 +c t ************/

proc reg data=kobdug;
 model LNGD85 = LNMH85 LNK85 t / p r dw;
run;

/******** OLS:LNGD85 =  a LNMH85 + b LNK85 +c t ************/
proc reg data=kobdug;
 model LNGD85 = LNMH85 LNK85 t /noint p r dw;
run;


/***************************************/
/**************** PART 2 ***************/
/***************************************/

/**** OLS: LN Y/L = C + LN K/L ******/

proc reg data=kobdug;
  model LNYL = LNKL/p r dw;
run;

/***** OLS: LN Y/L = C + T ********/
proc reg data=kobdug;
  model LNYL = T;
  model LNKL = T;
run;


/***** OLS: LN Y/L = C + LN K/L + T
proc reg data=kobdug;
  model LNYL = LNKL / p r dw;
run;


/**** Cochrane - Orcutt Method ****/


data cobb;
 input OBS    YEAR      LNYL        LNKL       T;
 CLNYL = LNYL - 0.454 * LAG1(LNYL);
 CLNKL = LNKL - 0.454 * LAG1(LNKL);

 CLNYLT = LNYL - 0.426 * LAG1(LNYL);
 CLNKLT = LNKL - 0.426 * LAG1(LNKL);
 ct = t-0.904723*lag1(t);
 drop OBS;
 cards;
                    1     70     -0.55315    -1.12906     1
                    2     71     -0.50692    -0.98832     2
                    3     72     -0.42320    -0.86312     3
                    4     73     -0.36538    -0.77224     4
                    5     74     -0.33084    -0.63820     5
                    6     75     -0.28009    -0.53010     6
                    7     76     -0.26287    -0.47757     7
                    8     77     -0.23091    -0.42309     8
                    9     78     -0.19897    -0.37757     9
                   10     79     -0.16328    -0.33452    10
                   11     80     -0.13530    -0.27730    11
                   12     81     -0.10464    -0.21813    12
                   13     82     -0.08136    -0.16613    13
                   14     83     -0.07197    -0.12733    14
                   15     84     -0.04469    -0.08422    15
                   16     85      0.00000     0.00000    16
                   17     86      0.02064     0.08118    17
                   18     87      0.04741     0.13651    18
                   19     88      0.09127     0.18621    19
                   20     89      0.12875     0.24077    20
                   21     90      0.17375     0.30897    21
                   22     91      0.21219     0.37976    22
                   23     92      0.23600     0.45950    23
;
run;

proc corr;
 var  LNYL  LNKL  T;
run;


/*proc reg simple;  */
/*  model LNYL = LNKL /p r dw;*/
/*    title 'OLS';*/
/*model LNYL = T;*/
/*model LNKL = T;*/
/*model LNYL = LNKL T /p r dw;*/
/*    title 'T_OLS';*/
/*run;*/

PROC PRINT DATA = COBB;
 VAR YEAR CLNYL CLNKL CLNYLT CLNKLT T ct;
RUN;

PROC REG;
  MODEL CLNYL = CLNKL/P R DW;
    title 'CO method';
  MODEL CLNYLT = CLNKLT ct/P R DW;
    title 'T_CO method';
RUN;


/*******GLS : by Prais Winsten Transformation *******/


TITLE 'Prais-Winsten ';
OPTIONS LS=78 PS=63;

data pw2;
 input OBS   YEAR PLNYL  PLNKL  PLNYLT  PLNKLT   T PWT PW;
 pt = t-0.904723 * lag1(t);
 drop OBS;
     
CARDS;
 1     70     -0.49285    -1.00599    -0.50044    -1.02148     1  0.904723 0.89100
 2     71     -0.25579    -0.47573    -0.27128    -0.50734     2  0.574    0.546
 3     72     -0.19306    -0.41442    -0.20725    -0.44210     3  0.574    0.546
 4     73     -0.17325    -0.38038    -0.18510    -0.40455     4  0.574    0.546
 5     74     -0.16496    -0.28760    -0.17519    -0.30923     5  0.574    0.546
 6     75     -0.12989    -0.24036    -0.13915    -0.25823     6  0.574    0.546
 7     76     -0.13571    -0.23690    -0.14355    -0.25175     7  0.574    0.546
 8     77     -0.11157    -0.20627    -0.11893    -0.21965     8  0.574    0.546
 9     78     -0.09414    -0.18549    -0.10060    -0.19733     9  0.574    0.546
10     79     -0.07295    -0.16310    -0.07852    -0.17368    10  0.574    0.546
11     80     -0.06117    -0.12543    -0.06574    -0.13479    11  0.574    0.546
12     81     -0.04321    -0.09224    -0.04700    -0.10000    12  0.574    0.546
13     82     -0.03385    -0.06710    -0.03678    -0.07321    13  0.574    0.546
14     83     -0.03503    -0.05191    -0.03731    -0.05656    14  0.574    0.546
15     84     -0.01202    -0.02641    -0.01403    -0.02998    15  0.574    0.546
16     85      0.02029     0.03824     0.01904     0.03588    16  0.574    0.546
17     86      0.02064     0.08118     0.02064     0.08118    17  0.574    0.546
18     87      0.03804     0.09965     0.03862     0.10193    18  0.574    0.546
19     88      0.06975     0.12423     0.07107     0.12806    19  0.574    0.546
20     89      0.08731     0.15623     0.08987     0.16144    20  0.574    0.546
21     90      0.11530     0.19966     0.11890     0.20640    21  0.574    0.546
22     91      0.13331     0.23949     0.13817     0.24814    22  0.574    0.546
23     92      0.13967     0.28709     0.14561     0.29772    23  0.574    0.546
;
RUN;


PROC PRINT DATA=PW2;
RUN;

PROC REG;
 MODEL PLNYL = PW PLNKL / P R DW NOINT;
 MODEL PLNYLT = PWT PLNKLT PT /P R DW NOINT;
RUN;