------------------------------------------------------------------------------------------------------
       log:  c:\Imbook\bwebpage\Section5\mma21p3panresiduals.txt
  log type:  text
 opened on:  23 May 2005, 13:01:06

. 
. ********** OVERVIEW OF MMA21P3PANRESIDUALS.DO **********
. 
. * STATA Program 
. * copyright C 2005 by A. Colin Cameron and Pravin K. Trivedi 
. * used for "Microeconometrics: Methods and Applications" 
. * by A. Colin Cameron and Pravin K. Trivedi (2005)
. * Cambridge University Press
. 
. * Chapter 21.3.4 pages 713-15 Residual analysis
. * This program 
. * (1) estimates correlations for 
. *     - dependent variable
. *     - regressors variable
. *     - residuals from pooled ols [Table 21.3]
. *     - residuals from within estimation [Table 21.4]
. *     - residuals from random effects estimation
. * (2) separately estimates correlations for
. *     - residuals from first differences estiamtion
. * (3) gets correlations for each individual observation
. 
. * The code is very limited:
. *   - it considers only one regressor
. *   - it assumes a balanced data set with exactly 10 years of data per obnservations
. *   - it does not use loops for transformations which would generalize code
. 
. * The four basic linear panel programs are
. *   mma21p1panfeandre.do    Linear fixed and random effects using xtreg
. *   mma21p2panfeandre.do    Linear fe and re using transformation and regress
. *                           plus also has valid Hausman test
. *   mma21p3panresiduals.do  Residual analysis after linear fe and re 
. *   mma21p4panpangls.do     Pooled panel OLS and GLS
. 
. * To run you need file
. *   MOM.dat    
. * in your directory
. 
. ********** SETUP **********
. 
. set more off

. version 8.0

. set scheme s1mono  /* Graphics scheme */

. 
. ********** DATA DESCRIPTION **********
. 
. *  The original data is from 
. *  Jim Ziliak (1997)
. *  "Efficient Estimation With Panel Data when Instruments are Predetermined: 
. * An Emprirical Comparison of Moment-Condition Estimators" 
. * Journal of Business and Economic Statistics, 15, 419-431
. 
. * File MOM.dat has data on 532 men over 10 years (1979-1988) 
. * Data are space-delimited ordered by person with separate line for each year
. * So id 1 1979, id 1 1980, ..., id 1 1988, id 2 1979, 1d 2 1980, ...
. * 8 variables: 
. * lnhr lnwg kids ageh agesq disab id year
. 
. * File MOM.dat is the version of the data posted at the JBES website
. * Note that in chapter 22 we instead use MOMprecise.dat
. * which is the same data set but with more significant digits
. 
. ********** READ DATA **********
. *
. * The data are in ascii file MOM.dat
. * There are 532 individuals with 10 lines (years) per individual
. * Read in using Infile: FREE FORMAT WITHOUT DICTIONARY
. infile lnhr lnwg kids ageh agesq disab id year using MOM.dat
(5320 observations read)

. summarize

    Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
        lnhr |      5320     7.65743    .2855914       2.77       8.56
        lnwg |      5320    2.609436    .4258924       -.26       4.69
        kids |      5320    1.555827    1.195924          0          6
        ageh |      5320    38.91823    8.450351         22         60
       agesq |      5320    1586.024    689.7759        484       3600
-------------+--------------------------------------------------------
       disab |      5320    .0609023    .2391734          0          1
          id |      5320       266.5    153.5893          1        532
        year |      5320      1983.5    2.872551       1979       1988

. 
. ************ (1) ANALYSIS: OBTAIN KEY AUTOCORRELATIONS Tables 21.3, 21.4 **********
. 
. ** RUN REGRESSIONS AND GET RESIDUALS OF INTEREST
. 
. * pooled ols
. regress lnhr lnwg

      Source |       SS       df       MS              Number of obs =    5320
-------------+------------------------------           F(  1,  5318) =   82.22
       Model |  6.60538417     1  6.60538417           Prob > F      =  0.0000
    Residual |  427.225206  5318  .080335691           R-squared     =  0.0152
-------------+------------------------------           Adj R-squared =  0.0150
       Total |  433.830591  5319  .081562435           Root MSE      =  .28344

------------------------------------------------------------------------------
        lnhr |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
        lnwg |   .0827436   .0091251     9.07   0.000     .0648545    .1006326
       _cons |   7.441516   .0241265   308.44   0.000     7.394219    7.488814
------------------------------------------------------------------------------

. predict upols, residuals

. 
. * fixed effects (within)
. xtreg lnhr lnwg, fe i(id)

Fixed-effects (within) regression               Number of obs      =      5320
Group variable (i): id                          Number of groups   =       532

R-sq:  within  = 0.0162                         Obs per group: min =        10
       between = 0.0213                                        avg =      10.0
       overall = 0.0152                                        max =        10

                                                F(1,4787)          =     78.96
corr(u_i, Xb)  = -0.1995                        Prob > F           =    0.0000

------------------------------------------------------------------------------
        lnhr |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
        lnwg |   .1676755     .01887     8.89   0.000     .1306816    .2046694
       _cons |   7.219892   .0493434   146.32   0.000     7.123156    7.316628
-------------+----------------------------------------------------------------
     sigma_u |  .18142881
     sigma_e |  .23278339
         rho |  .37789558   (fraction of variance due to u_i)
------------------------------------------------------------------------------
F test that all u_i=0:     F(531, 4787) =     5.83           Prob > F = 0.0000

. predict ufe, e

. 
. * random effects
. xtreg lnhr lnwg, re i(id)

Random-effects GLS regression                   Number of obs      =      5320
Group variable (i): id                          Number of groups   =       532

R-sq:  within  = 0.0162                         Obs per group: min =        10
       between = 0.0213                                        avg =      10.0
       overall = 0.0152                                        max =        10

Random effects u_i ~ Gaussian                   Wald chi2(1)       =     76.64
corr(u_i, X)       = 0 (assumed)                Prob > chi2        =    0.0000

------------------------------------------------------------------------------
        lnhr |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
        lnwg |   .1193322   .0136312     8.75   0.000     .0926155     .146049
       _cons |   7.346041   .0363925   201.86   0.000     7.274713    7.417368
-------------+----------------------------------------------------------------
     sigma_u |  .16124733
     sigma_e |  .23278339
         rho |  .32424354   (fraction of variance due to u_i)
------------------------------------------------------------------------------

. predict ure, e

. 
. summarize upols ufe ure

    Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
       upols |      5320   -1.27e-10    .2834089  -4.826247    .964581
         ufe |      5320   -5.52e-11    .2208354  -4.003929     1.2719
         ure |      5320   -9.00e-11    .2231118  -4.131111   1.085362

. save mom3, replace
file mom3.dta saved

. 
. ** TRANSFORM DATA FROM LONG FORM TO WIDE FORM
. 
. * Here just do this for lnhr and lnwg and the residuals 
. keep lnhr lnwg id year upols ufe ure

. reshape wide lnhr lnwg upols ufe ure, i(id) j(year)
(note: j = 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988)

Data                               long   ->   wide
-----------------------------------------------------------------------------
Number of obs.                     5320   ->     532
Number of variables                   7   ->      51
j variable (10 values)             year   ->   (dropped)
xij variables:
                                   lnhr   ->   lnhr1979 lnhr1980 ... lnhr1988
                                   lnwg   ->   lnwg1979 lnwg1980 ... lnwg1988
                                  upols   ->   upols1979 upols1980 ... upols1988
                                    ufe   ->   ufe1979 ufe1980 ... ufe1988
                                    ure   ->   ure1979 ure1980 ... ure1988
-----------------------------------------------------------------------------

. 
. * Since year is 1979 to 1988 this will create 
. * lnhr1979 to lnhr1988 and lnwg1979 to lnwg1988 
. 
. summarize

    Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
          id |       532       266.5    153.7194          1        532
    lnhr1979 |       532    7.669342     .249361       5.89       8.54
    lnwg1979 |       532    2.597763    .4188951        .52       4.62
   upols1979 |       532    .0128775    .2517228  -1.764168   .8312218
     ufe1979 |       532    .0138689    .2249175  -1.578105     1.2719
-------------+--------------------------------------------------------
     ure1979 |       532    .0133046    .2200196  -1.618987   1.085362
    lnhr1980 |       532    7.660094    .2691995       5.22       8.34
    lnwg1980 |       532    2.602368    .3945963         .8       4.61
   upols1980 |       532    .0032483    .2679463  -2.354734   .6659743
     ufe1980 |       532    .0038486    .2253673  -2.085636   1.128546
-------------+--------------------------------------------------------
     ure1980 |       532    .0035069    .2238723  -2.089847   .9429754
    lnhr1981 |       532     7.66765    .2105797       6.36        8.4
    lnwg1981 |       532    2.610959    .3870011       1.53       4.53
   upols1981 |       532    .0100939    .2133106  -1.342159   .7582438
     ufe1981 |       532    .0099646     .163407  -1.001722    1.03687
-------------+--------------------------------------------------------
     ure1981 |       532    .0100382    .1596593   -1.02491   .8517824
    lnhr1982 |       532     7.64609    .2427195       5.38       8.31
    lnwg1982 |       532     2.61468    .4014363       1.21       4.61
   upols1982 |       532   -.0117742    .2422735  -2.264238   .6897579
     ufe1982 |       532   -.0122196    .1890237  -1.623214   .7918997
-------------+--------------------------------------------------------
     ure1982 |       532   -.0119661    .1875585  -1.737484   .6666697
    lnhr1983 |       532    7.613064     .382703       2.77       8.37
    lnwg1983 |       532    2.610526    .4111869       1.08       4.62
   upols1983 |       532   -.0444568    .3778255  -4.826247   .7307264
     ufe1983 |       532   -.0445494    .2836351  -3.577253   .5196197
-------------+--------------------------------------------------------
     ure1983 |       532   -.0444967     .294545  -3.804399   .5078294
    lnhr1984 |       532    7.636523    .3316735       3.18       8.44
    lnwg1984 |       532    2.600188    .4621549       -.26       4.65
   upols1984 |       532   -.0201427    .3208512  -4.240003   .8263766
     ufe1984 |       532   -.0193572     .225836  -2.810104   .8327778
-------------+--------------------------------------------------------
     ure1984 |       532   -.0198043    .2378605  -3.140221   .7036628
    lnhr1985 |       532    7.668365    .2597423       5.08       8.54
    lnwg1985 |       532    2.614944    .4347554       1.33       4.69
   upols1985 |       532    .0104785     .259051  -2.503835   .8624523
     ufe1985 |       532    .0100107    .1856724  -1.581894   .7944546
-------------+--------------------------------------------------------
     ure1985 |       532     .010277    .1886509  -1.752727   .7370209
    lnhr1986 |       532    7.659286    .3330862       2.77       8.38
    lnwg1986 |       532    2.602632    .4432807        .07       4.59
   upols1986 |       532    .0024183    .3312105  -4.801424   .7439653
     ufe1986 |       532    .0029962    .2595405  -4.003929   .6384854
-------------+--------------------------------------------------------
     ure1986 |       532    .0026673     .264328  -4.131111   .5111209
    lnhr1987 |       532     7.67406    .2745015       4.38       8.56
    lnwg1987 |       532    2.614699    .4300122       1.28       4.03
   upols1987 |       532    .0161942    .2749153  -3.283269    .964581
     ufe1987 |       532    .0157472    .2141618  -2.817174   1.009662
-------------+--------------------------------------------------------
     ure1987 |       532    .0160016    .2148092  -2.897725   .8441463
    lnhr1988 |       532    7.679831    .2552894       4.79       8.53
    lnwg1988 |       532    2.625602    .4701759       -.22        4.6
   upols1988 |       532    .0210628    .2519891  -2.633313   .9072749
     ufe1988 |       532    .0196898    .2048927   -1.68379   1.123516
-------------+--------------------------------------------------------
     ure1988 |       532    .0204713    .2022375  -1.897506   .9393954

. 
. ** OBTAIN THE VARIOUS CORRELATIONS
. 
. corr lnhr1979 lnhr1980 lnhr1981 lnhr1982 lnhr1983 lnhr1984 lnhr1985 lnhr1986 lnhr1987 lnhr1988
(obs=532)

             | lnhr1979 lnhr1980 lnhr1981 lnhr1982 lnhr1983 lnhr1984 lnhr1985 lnhr1986 lnhr1987
-------------+---------------------------------------------------------------------------------
    lnhr1979 |   1.0000
    lnhr1980 |   0.3220   1.0000
    lnhr1981 |   0.4321   0.4022   1.0000
    lnhr1982 |   0.2947   0.3142   0.5670   1.0000
    lnhr1983 |   0.2070   0.2324   0.3788   0.4781   1.0000
    lnhr1984 |   0.1908   0.2235   0.3141   0.3318   0.6476   1.0000
    lnhr1985 |   0.2284   0.3184   0.3999   0.3453   0.3930   0.5839   1.0000
    lnhr1986 |   0.1934   0.1931   0.2813   0.2524   0.3162   0.3595   0.4128   1.0000
    lnhr1987 |   0.1986   0.3160   0.3322   0.2951   0.3261   0.3464   0.3987   0.3603   1.0000
    lnhr1988 |   0.1640   0.2551   0.3081   0.2674   0.2267   0.2537   0.3509   0.5741   0.5248

             | lnhr1988
-------------+---------
    lnhr1988 |   1.0000


. corr lnwg1979 lnwg1980 lnwg1981 lnwg1982 lnwg1983 lnwg1984 lnwg1985 lnwg1986 lnwg1987 lnwg1988
(obs=532)

             | lnwg1979 lnwg1980 lnwg1981 lnwg1982 lnwg1983 lnwg1984 lnwg1985 lnwg1986 lnwg1987
-------------+---------------------------------------------------------------------------------
    lnwg1979 |   1.0000
    lnwg1980 |   0.8415   1.0000
    lnwg1981 |   0.8283   0.8920   1.0000
    lnwg1982 |   0.7984   0.8559   0.9015   1.0000
    lnwg1983 |   0.7795   0.8408   0.8787   0.9155   1.0000
    lnwg1984 |   0.7208   0.7737   0.8102   0.8267   0.8625   1.0000
    lnwg1985 |   0.7424   0.7929   0.8290   0.8511   0.8636   0.8620   1.0000
    lnwg1986 |   0.7250   0.7714   0.8122   0.8286   0.8530   0.8399   0.9157   1.0000
    lnwg1987 |   0.7188   0.7639   0.8029   0.8282   0.8525   0.8681   0.9117   0.9111   1.0000
    lnwg1988 |   0.7220   0.7604   0.7900   0.8139   0.8326   0.8373   0.8787   0.8743   0.9101

             | lnwg1988
-------------+---------
    lnwg1988 |   1.0000


. * The following gives Table 21.3 p.714
. corr upols1979 upols1980 upols1981 upols1982 upols1983 upols1984 upols1985 upols1986 upols1987 upo
> ls1988
(obs=532)

             | upo~1979 upo~1980 upo~1981 upo~1982 upo~1983 upo~1984 upo~1985 upo~1986 upo~1987
-------------+---------------------------------------------------------------------------------
   upols1979 |   1.0000
   upols1980 |   0.3283   1.0000
   upols1981 |   0.4442   0.4035   1.0000
   upols1982 |   0.3008   0.3140   0.5678   1.0000
   upols1983 |   0.2089   0.2298   0.3739   0.4684   1.0000
   upols1984 |   0.2025   0.2289   0.3194   0.3360   0.6398   1.0000
   upols1985 |   0.2395   0.3246   0.4087   0.3484   0.3898   0.5800   1.0000
   upols1986 |   0.1987   0.1903   0.2797   0.2470   0.3109   0.3535   0.3991   1.0000
   upols1987 |   0.2091   0.3167   0.3340   0.2877   0.3097   0.3361   0.3941   0.3496   1.0000
   upols1988 |   0.1619   0.2456   0.3016   0.2582   0.2083   0.2470   0.3436   0.5545   0.5242

             | upo~1988
-------------+---------
   upols1988 |   1.0000


. corr ure1979 ure1980 ure1981 ure1982 ure1983 ure1984 ure1985 ure1986 ure1987 ure1988
(obs=532)

             |  ure1979  ure1980  ure1981  ure1982  ure1983  ure1984  ure1985  ure1986  ure1987
-------------+---------------------------------------------------------------------------------
     ure1979 |   1.0000
     ure1980 |   0.0778   1.0000
     ure1981 |   0.1777   0.0604   1.0000
     ure1982 |  -0.0250  -0.0519   0.2492   1.0000
     ure1983 |  -0.2339  -0.2277  -0.1609   0.0587   1.0000
     ure1984 |  -0.2482  -0.2431  -0.2691  -0.1709   0.3795   1.0000
     ure1985 |  -0.1842  -0.0919  -0.1054  -0.1581  -0.0939   0.2197   1.0000
     ure1986 |  -0.1860  -0.2333  -0.2434  -0.2405  -0.1110  -0.0763  -0.0361   1.0000
     ure1987 |  -0.1665  -0.0481  -0.1580  -0.1904  -0.1710  -0.1506  -0.0646  -0.0553   1.0000
     ure1988 |  -0.1960  -0.1251  -0.1646  -0.1949  -0.3265  -0.2786  -0.1221   0.2708   0.2379

             |  ure1988
-------------+---------
     ure1988 |   1.0000


. * The following gives Table 21.4 p.715
. corr ufe1979 ufe1980 ufe1981 ufe1982 ufe1983 ufe1984 ufe1985 ufe1986 ufe1987 ufe1988
(obs=532)

             |  ufe1979  ufe1980  ufe1981  ufe1982  ufe1983  ufe1984  ufe1985  ufe1986  ufe1987
-------------+---------------------------------------------------------------------------------
     ufe1979 |   1.0000
     ufe1980 |   0.1017   1.0000
     ufe1981 |   0.2082   0.0802   1.0000
     ufe1982 |   0.0003  -0.0380   0.2631   1.0000
     ufe1983 |  -0.2632  -0.2691  -0.2113   0.0089   1.0000
     ufe1984 |  -0.2594  -0.2698  -0.3004  -0.2037   0.3249   1.0000
     ufe1985 |  -0.1757  -0.0958  -0.1069  -0.1685  -0.1617   0.1713   1.0000
     ufe1986 |  -0.1915  -0.2534  -0.2644  -0.2676  -0.1723  -0.1364  -0.0865   1.0000
     ufe1987 |  -0.1519  -0.0497  -0.1561  -0.2008  -0.2399  -0.2066  -0.0918  -0.0908   1.0000
     ufe1988 |  -0.1650  -0.1109  -0.1385  -0.1772  -0.3816  -0.3096  -0.1268   0.2420   0.2439

             |  ufe1988
-------------+---------
     ufe1988 |   1.0000


. 
. * The following does estimation for just one year
. regress lnhr1979 lnwg1979

      Source |       SS       df       MS              Number of obs =     532
-------------+------------------------------           F(  1,   530) =    0.00
       Model |  .000035507     1  .000035507           Prob > F      =  0.9810
    Residual |  33.0180361   530  .062298181           R-squared     =  0.0000
-------------+------------------------------           Adj R-squared = -0.0019
       Total |  33.0180716   531  .062180926           Root MSE      =   .2496

------------------------------------------------------------------------------
    lnhr1979 |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
    lnwg1979 |   .0006173   .0258574     0.02   0.981    -.0501783    .0514129
       _cons |   7.667738   .0680375   112.70   0.000     7.534082    7.801395
------------------------------------------------------------------------------

. 
. ************ (2) ANALYSIS: OBTAIN AUTOCORRELATIONS FOR FIRST DIFFERNCES
. 
. ** SET UP THE DATA
. use mom, clear

. gen dlnhr = lnhr - lnhr[_n-1]
(1 missing value generated)

. gen dlnwg = lnwg - lnwg[_n-1]
(1 missing value generated)

. * The following drops the first year which here is 1979
. drop if year == 1979
(532 observations deleted)

. regress dlnhr dlnwg

      Source |       SS       df       MS              Number of obs =    4788
-------------+------------------------------           F(  1,  4786) =   26.09
       Model |  2.27870825     1  2.27870825           Prob > F      =  0.0000
    Residual |  417.943979  4786  .087326364           R-squared     =  0.0054
-------------+------------------------------           Adj R-squared =  0.0052
       Total |  420.222687  4787  .087784142           Root MSE      =  .29551

------------------------------------------------------------------------------
       dlnhr |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       dlnwg |   .1089851   .0213351     5.11   0.000     .0671584    .1508118
       _cons |   .0008283   .0042712     0.19   0.846    -.0075452    .0092018
------------------------------------------------------------------------------

. predict ufdiff, residuals

. * Here just do this for lnhr and lnwg and the residuals 
. keep dlnhr dlnwg ufdiff id year

. reshape wide dlnhr dlnwg ufdiff, i(id) j(year)
(note: j = 1980 1981 1982 1983 1984 1985 1986 1987 1988)

Data                               long   ->   wide
-----------------------------------------------------------------------------
Number of obs.                     4788   ->     532
Number of variables                   5   ->      28
j variable (9 values)              year   ->   (dropped)
xij variables:
                                  dlnhr   ->   dlnhr1980 dlnhr1981 ... dlnhr1988
                                  dlnwg   ->   dlnwg1980 dlnwg1981 ... dlnwg1988
                                 ufdiff   ->   ufdiff1980 ufdiff1981 ... ufdiff1988
-----------------------------------------------------------------------------

. summarize

    Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
          id |       532       266.5    153.7194          1        532
   dlnhr1980 |       532   -.0092481    .3023508       -2.5       1.71
   dlnwg1980 |       532    .0046053    .2301879      -2.12       1.05
  ufdiff1980 |       532   -.0105783    .3014161  -2.499738   1.690644
   dlnhr1981 |       532    .0075564    .2668644       -1.2       2.32
-------------+--------------------------------------------------------
   dlnwg1981 |       532    .0085902    .1818033       -.79       1.62
  ufdiff1981 |       532    .0057919    .2669213  -1.145188   2.343149
   dlnhr1982 |       532   -.0215602     .212834      -2.06       1.14
   dlnwg1982 |       532    .0037218    .1755574      -1.17        .74
  ufdiff1982 |       532   -.0227941     .213709  -2.036851   1.135902
-------------+--------------------------------------------------------
   dlnhr1983 |       532   -.0330263    .3413969      -4.51   .9899998
   dlnwg1983 |       532   -.0041541    .1673057       -.88   .6399999
  ufdiff1983 |       532   -.0334019    .3398726  -4.419281   .9780819
   dlnhr1984 |       532    .0234586    .3034213      -2.31       2.57
   dlnwg1984 |       532   -.0103383    .2342514      -2.13        .77
-------------+--------------------------------------------------------
  ufdiff1984 |       532    .0237571    .3004287  -2.168058   2.502691
   dlnhr1985 |       532    .0318421    .2772558      -1.46       3.52
   dlnwg1985 |       532    .0147556    .2371054      -1.33       3.06
  ufdiff1985 |       532    .0294057    .2697542  -1.315878   3.185677
   dlnhr1986 |       532   -.0090789    .3270724      -4.79        1.8
-------------+--------------------------------------------------------
   dlnwg1986 |       532    -.012312    .1804162      -1.83       1.04
  ufdiff1986 |       532   -.0085654    .3299129  -4.796278   1.789363
   dlnhr1987 |       532    .0147744    .3470122      -3.24       4.52
   dlnwg1987 |       532    .0120677    .1845692  -.9400001       1.95
  ufdiff1987 |       532    .0126309    .3494111  -3.243008   4.550777
-------------+--------------------------------------------------------
   dlnhr1988 |       532    .0057707    .2587991       -2.5       2.74
   dlnwg1988 |       532    .0109023     .194813       -1.5       1.22
  ufdiff1988 |       532    .0037542    .2576554  -2.337351   2.739172

. 
. ** GET THE CORRELATIONS
. corr dlnhr1980 dlnhr1981 dlnhr1982 dlnhr1983 dlnhr1984 dlnhr1985 dlnhr1986 dlnhr1987 dlnhr1988
(obs=532)

             | dlnhr1~0 dlnhr1~1 dlnhr1~2 dlnhr1~3 dlnhr1~4 dlnhr1~5 dlnhr1~6 dlnhr1~7 dlnhr1~8
-------------+---------------------------------------------------------------------------------
   dlnhr1980 |   1.0000
   dlnhr1981 |  -0.6289   1.0000
   dlnhr1982 |   0.0402  -0.2306   1.0000
   dlnhr1983 |   0.0144  -0.0204  -0.2209   1.0000
   dlnhr1984 |  -0.0001  -0.0570  -0.1410  -0.4495   1.0000
   dlnhr1985 |   0.0393  -0.0320  -0.0827  -0.4035  -0.1969   1.0000
   dlnhr1986 |  -0.0629   0.0322   0.0112   0.0233  -0.1192  -0.2334   1.0000
   dlnhr1987 |   0.0811  -0.0709  -0.0029  -0.0448  -0.0202   0.0093  -0.6231   1.0000
   dlnhr1988 |  -0.0341   0.0461  -0.0082  -0.1020   0.0261   0.0682   0.2486  -0.6064   1.0000


. corr dlnwg1980 dlnwg1981 dlnwg1982 dlnwg1983 dlnwg1984 dlnwg1985 dlnwg1986 dlnwg1987 dlnwg1988
(obs=532)

             | dlnwg1~0 dlnwg1~1 dlnwg1~2 dlnwg1~3 dlnwg1~4 dlnwg1~5 dlnwg1~6 dlnwg1~7 dlnwg1~8
-------------+---------------------------------------------------------------------------------
   dlnwg1980 |   1.0000
   dlnwg1981 |  -0.3507   1.0000
   dlnwg1982 |  -0.0149  -0.2849   1.0000
   dlnwg1983 |   0.0215  -0.0351  -0.3338   1.0000
   dlnwg1984 |  -0.0112   0.0098  -0.0686  -0.1899   1.0000
   dlnwg1985 |  -0.0135  -0.0085   0.0141  -0.1179  -0.5560   1.0000
   dlnwg1986 |  -0.0121   0.0289  -0.0303   0.0725  -0.0526  -0.2665   1.0000
   dlnwg1987 |  -0.0042  -0.0119   0.0382  -0.0083   0.1200  -0.1482  -0.5043   1.0000
   dlnwg1988 |  -0.0281  -0.0377   0.0157  -0.0133  -0.0174  -0.0058  -0.0174  -0.2627   1.0000


. corr ufdiff1980 ufdiff1981 ufdiff1982 ufdiff1983 ufdiff1984 ufdiff1985 ufdiff1986 ufdiff1987 ufdif
> f1988
(obs=532)

             | ufd~1980 ufd~1981 ufd~1982 ufd~1983 ufd~1984 ufd~1985 ufd~1986 ufd~1987 ufd~1988
-------------+---------------------------------------------------------------------------------
  ufdiff1980 |   1.0000
  ufdiff1981 |  -0.6263   1.0000
  ufdiff1982 |   0.0451  -0.2389   1.0000
  ufdiff1983 |   0.0128  -0.0239  -0.2316   1.0000
  ufdiff1984 |  -0.0010  -0.0588  -0.1291  -0.4804   1.0000
  ufdiff1985 |   0.0453  -0.0285  -0.0868  -0.3731  -0.1853   1.0000
  ufdiff1986 |  -0.0674   0.0321   0.0110   0.0256  -0.1138  -0.2538   1.0000
  ufdiff1987 |   0.0811  -0.0711  -0.0077  -0.0533  -0.0081   0.0211  -0.6250   1.0000
  ufdiff1988 |  -0.0323   0.0499   0.0022  -0.1019   0.0368   0.0543   0.2326  -0.5943   1.0000


. 
. ************ (3) ANALYSIS: CORRELATIONS FOR AN INDIVIDUAL OBSERVATION
. 
. * Look at correlations for each individual
. 
. ** TRANSFORM DATA FROM LONG FORM TO WIDE FORM FOR INDIVIDUALS
. 
. use mom3, replace

. * Here just do this for lnhr and lnwg and the residuals 
. keep lnhr lnwg id year

. reshape wide lnhr lnwg, i(year) j(id)
(note: j = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
>  34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 6
> 6 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 
> 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
>  124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 1
> 48 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
>  173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 1
> 97 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
>  222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 2
> 46 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270
>  271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 2
> 95 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319
>  320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 3
> 44 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368
>  369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 3
> 93 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417
>  418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 4
> 42 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466
>  467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 4
> 91 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515
>  516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532)

Data                               long   ->   wide
-----------------------------------------------------------------------------
Number of obs.                     5320   ->      10
Number of variables                   4   ->    1065
j variable (532 values)              id   ->   (dropped)
xij variables:
                                   lnhr   ->   lnhr1 lnhr2 ... lnhr532
                                   lnwg   ->   lnwg1 lnwg2 ... lnwg532
-----------------------------------------------------------------------------

. * Note that i and j are reversed
. 
. * Since year is 1979 to 1988 this will create 
. * lnhr1979 to lnhr1988 and lnwg1979 to lnwg1988 
. 
. tsset year
        time variable:  year, 1979 to 1988

. 
. * First-order Correlation over T years for the first observation
. corr lnhr1 L.lnhr1
(obs=9)

             |                 L.
             |    lnhr1    lnhr1
-------------+------------------
lnhr1        |
          -- |   1.0000
          L1 |   0.6378   1.0000


. * First-order Correlation over T years for the second observation
. corr lnhr2 L.lnhr2
(obs=9)

             |                 L.
             |    lnhr2    lnhr2
-------------+------------------
lnhr2        |
          -- |   1.0000
          L1 |   0.5553   1.0000


. * And so on
. 
. ********** CLOSE OUTPUT
. log close
       log:  c:\Imbook\bwebpage\Section5\mma21p3panresiduals.txt
  log type:  text
 closed on:  23 May 2005, 13:01:15
----------------------------------------------------------------------------------------------------
