Chapter 11 - Topics in Panel Data Models

Examples

-----------------------------------------------------------------------------------------------
      name:  SN
       log:  myReplications\iiexample11.smcl
  log type:  smcl
 opened on:   6 May 2020, 20:52:46
. **********************************************
. * Solomon Negash - Examples
. * Wooldridge (2010). Economic Analysis of Cross-Section and Panel Data. 2nd ed.  
. * STATA Program, version 16.1. 

. * Chapter 11  - More Topics in Linear Unobserved Effects Models
. ********************************************
. // Example 11.1 (Demand for Air Travel)
. bcuse airfare, clear nodesc
       panel variable:  id (strongly balanced)
        time variable:  year, 1997 to 2000
                delta:  1 unit

. xtset id year
       panel variable:  id (strongly balanced)
        time variable:  year, 1997 to 2000
                delta:  1 unit

. eststo RE: qui xtreg lpassen lfare ldist ldistsq i.year, re 

. eststo FE: qui xtreg lpassen lfare ldist ldistsq i.year, fe 

. eststo REIV: qui xtivreg lpassen (lfare=concen) ldist ldistsq i.year, re 

. eststo FEIV: qui xtivreg lpassen (lfare=concen) ldist ldistsq i.year, fe 

. estout, keep(lfare ldist ldistsq) cells(b(nostar fmt(4)) se(par fmt(4))) stats(N, /// 
 fmt(%9.0g) labels(N)) varlabels(_cons constant) varwidth(10) ti("Table 11.1 Passenger /// 
 Demand Model, United States Domestic Routes, 1997-2000")

Table 11.1 Passenger Demand Model, United States Domestic Routes, 1997-2000
--------------------------------------------------------------
                     RE           FE         REIV         FEIV
                   b/se         b/se         b/se         b/se
--------------------------------------------------------------
lfare           -1.1025      -1.1550      -0.5079      -0.3016
               (0.0220)     (0.0228)     (0.2297)     (0.2774)
ldist           -1.9707       0.0000      -1.5048       0.0000
               (0.6474)          (.)     (0.6933)          (.)
ldistsq          0.1710       0.0000       0.1176       0.0000
               (0.0489)          (.)     (0.0546)          (.)
--------------------------------------------------------------
N                  4596         4596         4596         4596
--------------------------------------------------------------

. eststo clear  





. // Example 11.2 (Effects of Prison Population on Crime Rates): 
. bcuse prison, clear nodesc

. xtset state year
       panel variable:  state (strongly balanced)
        time variable:  year, 80 to 93
                delta:  1 unit


. global dZ " gpolpc gincpc cag0_14 cag15_17 cag18_24 cag25_34 cunem cblack cmetro " 


. *POLS
. reg gpris  final1 final2 $dZ i.year, cluster(state)

Linear regression                               Number of obs     =        714
                                                F(24, 50)         =       9.27
                                                Prob > F          =     0.0000
                                                R-squared         =     0.1522
                                                Root MSE          =     .06237

                                 (Std. Err. adjusted for 51 clusters in state)
------------------------------------------------------------------------------
             |               Robust
       gpris |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
      final1 |   -.077488   .0164372    -4.71   0.000    -.1105032   -.0444729
      final2 |  -.0529558   .0160327    -3.30   0.002    -.0851585   -.0207531
      gpolpc |  -.0286921   .0305312    -0.94   0.352    -.0900159    .0326316
      gincpc |   .2095521   .1597362     1.31   0.196    -.1112875    .5303918
     cag0_14 |   2.617307   2.029707     1.29   0.203     -1.45948    6.694094
    cag15_17 |  -1.608738   4.138375    -0.39   0.699    -9.920908    6.703433
    cag18_24 |   .9533678   1.640538     0.58   0.564    -2.341749    4.248485
    cag25_34 |  -1.031684   1.945366    -0.53   0.598    -4.939067      2.8757
       cunem |   .1616595    .280673     0.58   0.567    -.4020888    .7254077
      cblack |  -.0044763   .0266392    -0.17   0.867    -.0579828    .0490301
      cmetro |  -1.418389   .7425213    -1.91   0.062    -2.909787    .0730092
             |
        year |
         81  |   .0124113    .013231     0.94   0.353    -.0141641    .0389866
         82  |   .0773503   .0210098     3.68   0.001     .0351508    .1195498
         83  |   .0767785   .0182621     4.20   0.000     .0400981    .1134589
         84  |   .0289763   .0187158     1.55   0.128    -.0086156    .0665682
         85  |   .0279051   .0175829     1.59   0.119    -.0074112    .0632214
         86  |   .0541489   .0216701     2.50   0.016     .0106233    .0976746
         87  |   .0312716   .0181202     1.73   0.091    -.0051238    .0676671
         88  |    .019245    .020214     0.95   0.346    -.0213561     .059846
         89  |   .0184651    .020502     0.90   0.372    -.0227143    .0596445
         90  |   .0635926   .0192973     3.30   0.002     .0248328    .1023524
         91  |   .0263719   .0216737     1.22   0.229     -.017161    .0699049
         92  |   .0190481   .0207525     0.92   0.363    -.0226345    .0607307
         93  |   .0134109   .0223509     0.60   0.551    -.0314821     .058304
             |
       _cons |   .0272013   .0224292     1.21   0.231     -.017849    .0722516
------------------------------------------------------------------------------

. test final1 final2

 ( 1)  final1 = 0
 ( 2)  final2 = 0

       F(  2,    50) =   18.82
            Prob > F =    0.0000


. *2SLS
. ivregress 2sls gcriv (gpris = final1 final2) $dZ i.year,  cluster(state)

Instrumental variables (2SLS) regression          Number of obs   =        714
                                                  Wald chi2(23)   =     472.56
                                                  Prob > chi2     =     0.0000
                                                  R-squared       =          .
                                                  Root MSE        =     .09385

                                 (Std. Err. adjusted for 51 clusters in state)
------------------------------------------------------------------------------
             |               Robust
       gcriv |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       gpris |  -1.031956    .207932    -4.96   0.000    -1.439496   -.6244172
      gpolpc |    .035315   .0535658     0.66   0.510    -.0696721    .1403021
      gincpc |   .9101992   .3287881     2.77   0.006     .2657864    1.554612
     cag0_14 |   3.379384   2.382372     1.42   0.156     -1.28998    8.048748
    cag15_17 |   3.549945   5.316435     0.67   0.504    -6.870076    13.96997
    cag18_24 |   3.358348   3.162501     1.06   0.288     -2.84004    9.556735
    cag25_34 |   2.319993   3.164199     0.73   0.463    -3.881724    8.521709
       cunem |   .5236958   .4626663     1.13   0.258    -.3831136    1.430505
      cblack |  -.0158476   .0298869    -0.53   0.596    -.0744248    .0427296
      cmetro |   -.591517   1.244729    -0.48   0.635    -3.031142    1.848108
             |
        year |
         81  |  -.0560732   .0242701    -2.31   0.021    -.1036417   -.0085047
         82  |   .0284616   .0363238     0.78   0.433    -.0427317    .0996549
         83  |    .024703   .0329137     0.75   0.453    -.0398066    .0892126
         84  |   .0128703   .0287645     0.45   0.655    -.0435071    .0692477
         85  |   .0354026   .0229062     1.55   0.122    -.0094927    .0802979
         86  |   .0921857   .0310599     2.97   0.003     .0313093    .1530621
         87  |    .004771   .0285119     0.17   0.867    -.0511112    .0606532
         88  |   .0532706     .02854     1.87   0.062    -.0026668    .1092079
         89  |   .0430862   .0310542     1.39   0.165    -.0177789    .1039513
         90  |   .1442652    .034542     4.18   0.000     .0765642    .2119662
         91  |   .0618481   .0288607     2.14   0.032     .0052822    .1184139
         92  |   .0266574   .0304146     0.88   0.381    -.0329542     .086269
         93  |   .0222739   .0335942     0.66   0.507    -.0435695    .0881174
             |
       _cons |   .0148377   .0350424     0.42   0.672    -.0538441    .0835195
------------------------------------------------------------------------------
Instrumented:  gpris
Instruments:   gpolpc gincpc cag0_14 cag15_17 cag18_24 cag25_34 cunem cblack
               cmetro 81.year 82.year 83.year 84.year 85.year 86.year
               87.year 88.year 89.year 90.year 91.year 92.year 93.year
               final1 final2





. *POLS on FD
. regress gcriv gpris $dZ i.year,  cluster(state)

Linear regression                               Number of obs     =        714
                                                F(23, 50)         =      21.54
                                                Prob > F          =     0.0000
                                                R-squared         =     0.2311
                                                Root MSE          =     .07893

                                 (Std. Err. adjusted for 51 clusters in state)
------------------------------------------------------------------------------
             |               Robust
       gcriv |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       gpris |  -.1808974   .0487909    -3.71   0.001    -.2788967    -.082898
      gpolpc |   .0514239    .047601     1.08   0.285    -.0441854    .1470333
      gincpc |   .7383676   .2457843     3.00   0.004     .2446953     1.23204
     cag0_14 |    .989306    1.86767     0.53   0.599    -2.762019    4.740631
    cag15_17 |    4.98384   4.758174     1.05   0.300    -4.573234    14.54091
    cag18_24 |   2.412758    3.33858     0.72   0.473    -4.292978    9.118493
    cag25_34 |   2.879946    2.61131     1.10   0.275    -2.365025    8.124917
       cunem |     .41126   .3824013     1.08   0.287    -.3568156    1.179335
      cblack |  -.0147435   .0147599    -1.00   0.323    -.0443896    .0149027
      cmetro |   .5383056   1.112491     0.48   0.631    -1.696199     2.77281
             |
        year |
         81  |  -.0686258   .0205187    -3.34   0.002    -.1098389   -.0274128
         82  |  -.0407726   .0245867    -1.66   0.104    -.0901564    .0086112
         83  |  -.0421775   .0244289    -1.73   0.090    -.0912445    .0068894
         84  |  -.0136596   .0234198    -0.58   0.562    -.0606996    .0333804
         85  |   .0094042   .0179408     0.52   0.602     -.026631    .0454394
         86  |   .0440948   .0223957     1.97   0.055    -.0008883    .0890778
         87  |  -.0239597   .0233962    -1.02   0.311    -.0709523     .023033
         88  |   .0347581   .0220287     1.58   0.121    -.0094878    .0790039
         89  |   .0253571   .0263778     0.96   0.341    -.0276243    .0783385
         90  |   .0871704   .0253365     3.44   0.001     .0362805    .1380603
         91  |    .038884   .0198436     1.96   0.056     -.000973    .0787411
         92  |   .0081502    .022614     0.36   0.720    -.0372713    .0535718
         93  |   .0087141   .0239587     0.36   0.718    -.0394083    .0568365
             |
       _cons |  -.0056706   .0258729    -0.22   0.827    -.0576377    .0462966
------------------------------------------------------------------------------


. *FD test
. regress gpris final1 final2 $dZ i.year,  cluster(state)

Linear regression                               Number of obs     =        714
                                                F(24, 50)         =       9.27
                                                Prob > F          =     0.0000
                                                R-squared         =     0.1522
                                                Root MSE          =     .06237

                                 (Std. Err. adjusted for 51 clusters in state)
------------------------------------------------------------------------------
             |               Robust
       gpris |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
      final1 |   -.077488   .0164372    -4.71   0.000    -.1105032   -.0444729
      final2 |  -.0529558   .0160327    -3.30   0.002    -.0851585   -.0207531
      gpolpc |  -.0286921   .0305312    -0.94   0.352    -.0900159    .0326316
      gincpc |   .2095521   .1597362     1.31   0.196    -.1112875    .5303918
     cag0_14 |   2.617307   2.029707     1.29   0.203     -1.45948    6.694094
    cag15_17 |  -1.608738   4.138375    -0.39   0.699    -9.920908    6.703433
    cag18_24 |   .9533678   1.640538     0.58   0.564    -2.341749    4.248485
    cag25_34 |  -1.031684   1.945366    -0.53   0.598    -4.939067      2.8757
       cunem |   .1616595    .280673     0.58   0.567    -.4020888    .7254077
      cblack |  -.0044763   .0266392    -0.17   0.867    -.0579828    .0490301
      cmetro |  -1.418389   .7425213    -1.91   0.062    -2.909787    .0730092
             |
        year |
         81  |   .0124113    .013231     0.94   0.353    -.0141641    .0389866
         82  |   .0773503   .0210098     3.68   0.001     .0351508    .1195498
         83  |   .0767785   .0182621     4.20   0.000     .0400981    .1134589
         84  |   .0289763   .0187158     1.55   0.128    -.0086156    .0665682
         85  |   .0279051   .0175829     1.59   0.119    -.0074112    .0632214
         86  |   .0541489   .0216701     2.50   0.016     .0106233    .0976746
         87  |   .0312716   .0181202     1.73   0.091    -.0051238    .0676671
         88  |    .019245    .020214     0.95   0.346    -.0213561     .059846
         89  |   .0184651    .020502     0.90   0.372    -.0227143    .0596445
         90  |   .0635926   .0192973     3.30   0.002     .0248328    .1023524
         91  |   .0263719   .0216737     1.22   0.229     -.017161    .0699049
         92  |   .0190481   .0207525     0.92   0.363    -.0226345    .0607307
         93  |   .0134109   .0223509     0.60   0.551    -.0314821     .058304
             |
       _cons |   .0272013   .0224292     1.21   0.231     -.017849    .0722516
------------------------------------------------------------------------------

. predict u, r

. regress gcriv u gpris $dZ i.year,  cluster(state)

Linear regression                               Number of obs     =        714
                                                F(24, 50)         =      25.60
                                                Prob > F          =     0.0000
                                                R-squared         =     0.2400
                                                Root MSE          =     .07854

                                 (Std. Err. adjusted for 51 clusters in state)
------------------------------------------------------------------------------
             |               Robust
       gcriv |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
           u |   .8722033   .2863926     3.05   0.004     .2969669     1.44744
       gpris |  -1.031956   .2860424    -3.61   0.001    -1.606489   -.4574233
      gpolpc |    .035315   .0472484     0.75   0.458    -.0595862    .1302162
      gincpc |   .9101992   .2552867     3.57   0.001     .3974407    1.422958
     cag0_14 |   3.379384   1.916788     1.76   0.084    -.4705977    7.229365
    cag15_17 |   3.549945    4.68874     0.76   0.453    -5.867667    12.96756
    cag18_24 |   3.358348   3.197546     1.05   0.299    -3.064113    9.780809
    cag25_34 |   2.319992    2.47294     0.94   0.353    -2.647053    7.287038
       cunem |   .5236958   .3758529     1.39   0.170    -.2312271    1.278619
      cblack |  -.0158476   .0150409    -1.05   0.297     -.046058    .0143629
      cmetro |   -.591517   1.179474    -0.50   0.618     -2.96056    1.777526
             |
        year |
         81  |  -.0560732   .0223056    -2.51   0.015    -.1008753   -.0112711
         82  |   .0284616   .0334096     0.85   0.398    -.0386436    .0955668
         83  |    .024703   .0329819     0.75   0.457    -.0415431    .0909491
         84  |   .0128703   .0239878     0.54   0.594    -.0353105    .0610512
         85  |   .0354026   .0181678     1.95   0.057    -.0010885    .0718937
         86  |   .0921857   .0243155     3.79   0.000     .0433465    .1410248
         87  |    .004771   .0235578     0.20   0.840    -.0425463    .0520883
         88  |   .0532706   .0227985     2.34   0.024     .0074785    .0990627
         89  |   .0430862   .0256412     1.68   0.099    -.0084157    .0945882
         90  |   .1442652   .0294413     4.90   0.000     .0851306    .2033998
         91  |   .0618481   .0204929     3.02   0.004     .0206868    .1030093
         92  |   .0266574   .0217981     1.22   0.227    -.0171254    .0704402
         93  |   .0222739   .0235782     0.94   0.349    -.0250844    .0696322
             |
       _cons |   .0148377   .0252115     0.59   0.559    -.0358011    .0654765
------------------------------------------------------------------------------

 



. // Example 11.3 (Estimating a Dynamic Airfare Equation)
. bcuse airfare, clear nodesc
       panel variable:  id (strongly balanced)
        time variable:  year, 1997 to 2000
                delta:  1 unit

. xtset id year
       panel variable:  id (strongly balanced)
        time variable:  year, 1997 to 2000
                delta:  1 unit

. eststo PooledOLS: reg d.lfare l.d.lfare d.concen y99 y00, r
note: y00 omitted because of collinearity

Linear regression                               Number of obs     =      2,298
                                                F(3, 2294)        =      42.65
                                                Prob > F          =     0.0000
                                                R-squared         =     0.0651
                                                Root MSE          =      .1168

------------------------------------------------------------------------------
             |               Robust
     D.lfare |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       lfare |
         LD. |  -.1264673    .027075    -4.67   0.000    -.1795613   -.0733732
             |
      concen |
         D1. |   .0762671   .0488802     1.56   0.119     -.019587    .1721212
             |
         y99 |  -.0473536   .0048179    -9.83   0.000    -.0568015   -.0379056
         y00 |          0  (omitted)
       _cons |   .0624434   .0033052    18.89   0.000     .0559618     .068925
------------------------------------------------------------------------------


. qui reg l.d.lfare l2.lfare if year==1999

. predict ivu1, r 
(2,298 missing values generated)

. qui reg l.d.lfare l2.lfare l3.lfare if year==2000

. predict ivu2, r 
(3,447 missing values generated)

. eststo PooledIV: ivreg d.lfare (d.l.lfare = ivu1 ivu2 ) d.concen , r  

Instrumental variables (2SLS) regression        Number of obs     =      1,149
                                                F(2, 1146)        =      12.10
                                                Prob > F          =     0.0000
                                                R-squared         =     0.0527
                                                Root MSE          =     .11039

------------------------------------------------------------------------------
             |               Robust
     D.lfare |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       lfare |
         LD. |  -.2294362   .0493063    -4.65   0.000     -.326177   -.1326955
             |
      concen |
         D1. |  -.0929553   .0531162    -1.75   0.080    -.1971712    .0112606
             |
       _cons |   .0629919   .0032858    19.17   0.000     .0565451    .0694387
------------------------------------------------------------------------------
Instrumented:  LD.lfare
Instruments:   D.concen ivu1 ivu2
------------------------------------------------------------------------------

.    
. eststo Arellano_Bond: xtabond lfare concen y00 y99, lag(1)

Arellano-Bond dynamic panel-data estimation     Number of obs     =      2,298
Group variable: id                              Number of groups  =      1,149
Time variable: year
                                                Obs per group:
                                                              min =          2
                                                              avg =          2
                                                              max =          2

Number of instruments =      7                  Wald chi2(4)      =     441.62
                                                Prob > chi2       =     0.0000
One-step results
------------------------------------------------------------------------------
       lfare |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       lfare |
         L1. |   .3326355   .0548124     6.07   0.000     .2252051    .4400659
             |
      concen |   .1519406   .0399507     3.80   0.000     .0736386    .2302425
         y00 |   .0629313   .0043475    14.48   0.000     .0544103    .0714523
         y99 |   .0051715   .0041216     1.25   0.210    -.0029066    .0132496
       _cons |   3.304619   .2820506    11.72   0.000      2.75181    3.857428
------------------------------------------------------------------------------
Instruments for differenced equation
        GMM-type: L(2/.).lfare
        Standard: D.concen D.y00 D.y99
Instruments for level equation
        Standard: _cons

. estout PooledOLS PooledIV Arellano_Bond, cells(b(nostar fmt(4)) se(par fmt(4))) stats(N, ///
fmt(%9.0g) labels(N) ti("Table 2.1 Dynamic Airfare Model, First Differencing IV Estimation"))

Table 2.1 Dynamic Airfare Model, First Differencing IV Estimation
---------------------------------------------------
                PooledOLS     PooledIV Arellano_B~d
                     b/se         b/se         b/se
---------------------------------------------------
LD.lfare          -0.1265      -0.2294             
                 (0.0271)     (0.0493)             
L.lfare                                      0.3326
                                           (0.0548)
D.concen           0.0763      -0.0930             
                 (0.0489)     (0.0531)             
concen                                       0.1519
                                           (0.0400)
y99               -0.0474                    0.0052
                 (0.0048)                  (0.0041)
y00                0.0000                    0.0629
                      (.)                  (0.0043)
_cons              0.0624       0.0630       3.3046
                 (0.0033)     (0.0033)     (0.2821)
---------------------------------------------------
N                    2298         1149         2298
---------------------------------------------------

. eststo clear 






. // Example 11.4 (Random Growth Model for Analyzing Enterprise Zones)
. bcuse ezunem, clear nodesc

. xtset city year
       panel variable:  city (strongly balanced)
        time variable:  year, 1980 to 1988
                delta:  1 unit

. xtreg d.luclms d.ez i.year, fe 

Fixed-effects (within) regression               Number of obs     =        176
Group variable: city                            Number of groups  =         22

R-sq:                                           Obs per group:
     within  = 0.6373                                         min =          8
     between = 0.0094                                         avg =        8.0
     overall = 0.6230                                         max =          8

                                                F(8,146)          =      32.06
corr(u_i, Xb)  = -0.0060                        Prob > F          =     0.0000

------------------------------------------------------------------------------
    D.luclms |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
          ez |
         D1. |  -.1919386   .0849905    -2.26   0.025    -.3599093    -.023968
             |
        year |
       1982  |   .7787587   .0675785    11.52   0.000     .6452003    .9123172
       1983  |  -.0331199   .0675785    -0.49   0.625    -.1666784    .1004386
       1984  |  -.0143949   .0714432    -0.20   0.841    -.1555913    .1268016
       1985  |   .3249093   .0693228     4.69   0.000     .1879036     .461915
       1986  |   .2921541   .0675785     4.32   0.000     .1585956    .4257126
       1987  |   .0539477   .0675785     0.80   0.426    -.0796108    .1875062
       1988  |  -.0170527   .0675785    -0.25   0.801    -.1506111    .1165058
             |
       _cons |  -.3216314   .0477852    -6.73   0.000    -.4160715   -.2271913
-------------+----------------------------------------------------------------
     sigma_u |   .0524516
     sigma_e |  .22413255
         rho |  .05192204   (fraction of variance due to u_i)
------------------------------------------------------------------------------
F test that all u_i=0: F(21, 146) = 0.44                     Prob > F = 0.9849

. *Alternatively 
. xtreg  guclms cez i.year, fe

Fixed-effects (within) regression               Number of obs     =        176
Group variable: city                            Number of groups  =         22

R-sq:                                           Obs per group:
     within  = 0.6373                                         min =          8
     between = 0.0094                                         avg =        8.0
     overall = 0.6230                                         max =          8

                                                F(8,146)          =      32.06
corr(u_i, Xb)  = -0.0060                        Prob > F          =     0.0000

------------------------------------------------------------------------------
      guclms |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
         cez |  -.1919402   .0849908    -2.26   0.025    -.3599113    -.023969
             |
        year |
       1982  |   .7787595   .0675787    11.52   0.000     .6452006    .9123184
       1983  |  -.0331192   .0675787    -0.49   0.625    -.1666781    .1004397
       1984  |  -.0143939   .0714434    -0.20   0.841    -.1555908     .126803
       1985  |   .3249105    .069323     4.69   0.000     .1879044    .4619167
       1986  |    .292154   .0675787     4.32   0.000     .1585951    .4257128
       1987  |   .0539481   .0675787     0.80   0.426    -.0796108     .187507
       1988  |  -.0170526   .0675787    -0.25   0.801    -.1506115    .1165063
             |
       _cons |  -.3216319   .0477854    -6.73   0.000    -.4160723   -.2271915
-------------+----------------------------------------------------------------
     sigma_u |  .05245175
     sigma_e |  .22413321
         rho |  .05192202   (fraction of variance due to u_i)
------------------------------------------------------------------------------
F test that all u_i=0: F(21, 146) = 0.44                     Prob > F = 0.9849

 




. // Example 11.5 (Testing for Correlated Random Slopes in a Passenger Demand Equation)
. bcuse airfare, clear nodesc
       panel variable:  id (strongly balanced)
        time variable:  year, 1997 to 2000
                delta:  1 unit

. xtset id year
       panel variable:  id (strongly balanced)
        time variable:  year, 1997 to 2000
                delta:  1 unit

. by id: egen mconcen=mean(concen)

. g lfare_cbar = mcon*lfare

. g concen_cbar = mcon*concen

. xtivreg lpassen (lfare lfare_cbar = concen  concen_cbar ) i.year, fe vce(cluster id)

Fixed-effects (within) IV regression            Number of obs     =      4,596
Group variable: id                              Number of groups  =      1,149

R-sq:                                           Obs per group:
     within  =      .                                         min =          4
     between = 0.0014                                         avg =        4.0
     overall = 0.0013                                         max =          4


                                                Wald chi2(5)      =      32.82
corr(u_i, Xb)  = -0.9965                        Prob > chi2       =     0.0000

                                 (Std. Err. adjusted for 1,149 clusters in id)
------------------------------------------------------------------------------
             |               Robust
     lpassen |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       lfare |   7.928977   14.48312     0.55   0.584    -20.45742    36.31538
  lfare_cbar |  -11.04633   18.55033    -0.60   0.552    -47.40431    25.31165
             |
        year |
       1998  |   .0138466   .0410113     0.34   0.736    -.0665341    .0942272
       1999  |   .0725267   .0365297     1.99   0.047     .0009298    .1441236
       2000  |   .0468379   .1846637     0.25   0.800    -.3150963     .408772
             |
       _cons |  -.2900056   16.64715    -0.02   0.986    -32.91783    32.33782
-------------+----------------------------------------------------------------
     sigma_u |  10.772971
     sigma_e |  .33205881
         rho |  .99905082   (fraction of variance due to u_i)
------------------------------------------------------------------------------
Instrumented:   lfare lfare_cbar
Instruments:    1998.year 1999.year 2000.year concen concen_cbar
------------------------------------------------------------------------------


. log close 
      name:  SN
       log:  myReplications\iiexample11.smcl
  log type:  smcl
 closed on:   6 May 2020, 20:52:56
-----------------------------------------------------------------------------------------------