Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Fixed effect model with a lagged covariate and an unbalanced panel dataset

    Hi,

    I plan on using the xtewreg package so I have to use demeaned data. My actual data is an unbalanced panel. In order to make sure my estimates were correct I compared the results of the regress and xtreg packages. There is hardly any difference between the coefficients of regress and xtreg when I don't included a lagged covariate. However, I noticed discrepancies across results when I lagged a covariate. I have included a reproducible example below to illustrate my observations.

    Questions:
    1. If the researcher plans on using a lagged covariate and needs to demean the data, is the process to lag by unit first then demean or demean first then lag by unit?
    2. Why are my coefficients different when I use l1.mvalue versus when I used a manually created lag variable l_mvalue with xtreg? I'm not sure which method is best or correct.
    Code:
    clear all
    webuse grunfeld, clear
    *******************************************
    * using balanced panel
    
    xtset company year
    
    * demean the data
    * 1st way
    foreach var of varlist invest mvalue kstock {    
      bysort company : egen mean_`var'_comp = mean(`var')
        gen dm_`var' = `var' - mean_`var'_comp
        }
    
    bysort company : generate dm_l_mvalue = l1.dm_mvalue
    
    * 2nd way
    bysort company : generate l_mvalue = l1.mvalue
    bysort company : egen mean_l_mvalue_comp = mean(l_mvalue)
    gen dm2_l_mvalue = l_mvalue - mean_l_mvalue_comp
        
    * Fixed Effects (Company) without lags
    regress dm_invest dm_mvalue
    xtreg invest mvalue, fe
    
    * Fixed Effects (Company) with lags
    regress dm_invest dm_l_mvalue
    regress dm_invest dm2_l_mvalue
    xtreg invest l_mvalue, fe
    xtreg invest l1.mvalue, fe
    
    * Fixed Effects (Company) with lags
    regress dm_invest dm_l_mvalue dm_kstock
    regress dm_invest dm2_l_mvalue dm_kstock
    xtreg invest l_mvalue kstock, fe
    xtreg invest l1.mvalue kstock, fe
    
    *******************************************
    * using unbalanced panel
    
    drop in 5
    drop in 32
    drop in 33
    drop in 34
    drop in 62
    drop in 63
    drop in 64
    drop in 65
    drop in 152
    drop in 189
    xtset company year
    
    * Fixed Effects (Company) without lags
    regress dm_invest dm_mvalue
    xtreg invest mvalue, fe
    
    * Fixed Effects (Company) with lags
    regress dm_invest dm_l_mvalue
    regress dm_invest dm2_l_mvalue
    xtreg invest l_mvalue, fe
    xtreg invest l1.mvalue, fe
    
    * Fixed Effects (Company) with lags
    regress dm_invest dm_l_mvalue dm_kstock
    regress dm_invest dm2_l_mvalue dm_kstock
    xtreg invest l_mvalue kstock, fe
    xtreg invest l1.mvalue kstock, fe

  • #2
    You need to consider that the demeaning sample in the presence of a lagged variable is not the full sample. With unbalanced panels, you will require iterative demeaning to get the correct FE coefficients. See https://www.statalist.org/forums/for...-time-variable


    Code:
    webuse grunfeld, clear
    gen lkstock= L.kstock
    xtreg invest mvalue L.kstock, fe
    foreach var of varlist invest mvalue lkstock{
       bysort company : egen mean_`var'_comp = mean(`var') if e(sample)
       gen dm_`var' = `var' - mean_`var'_comp if e(sample)
    }
    regress dm_invest dm_mvalue dm_lkstock
    Res.:

    Code:
    . xtreg invest mvalue L.kstock, fe
    
    Fixed-effects (within) regression               Number of obs     =        190
    Group variable: company                         Number of groups  =         10
    
    R-sq:                                           Obs per group:
         within  = 0.7095                                         min =         19
         between = 0.8222                                         avg =       19.0
         overall = 0.7940                                         max =         19
    
                                                    F(2,178)          =     217.39
    corr(u_i, Xb)  = -0.2950                        Prob > F          =     0.0000
    
    ------------------------------------------------------------------------------
          invest |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
          mvalue |   .1253334   .0137449     9.12   0.000     .0982095    .1524572
                 |
          kstock |
             L1. |   .3398507   .0225361    15.08   0.000     .2953783    .3843231
                 |
           _cons |  -75.43141   15.07658    -5.00   0.000    -105.1832   -45.67958
    -------------+----------------------------------------------------------------
         sigma_u |  90.759113
         sigma_e |  58.574631
             rho |  .70595411   (fraction of variance due to u_i)
    ------------------------------------------------------------------------------
    F test that all u_i=0: F(9, 178) = 40.20                     Prob > F = 0.0000
    
    
    .
    . regress dm_invest dm_mvalue dm_lkstock
    
          Source |       SS           df       MS      Number of obs   =       190
    -------------+----------------------------------   F(2, 187)       =    228.38
           Model |  1491691.73         2  745845.863   Prob > F        =    0.0000
        Residual |  610715.747       187  3265.85961   R-squared       =    0.7095
    -------------+----------------------------------   Adj R-squared   =    0.7064
           Total |  2102407.47       189  11123.8491   Root MSE        =    57.148
    
    ------------------------------------------------------------------------------
       dm_invest |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
       dm_mvalue |   .1253334     .01341     9.35   0.000      .098879    .1517877
      dm_lkstock |   .3398507   .0219871    15.46   0.000      .296476    .3832254
           _cons |   4.64e-06    4.14593     0.00   1.000      -8.1788    8.178809
    ------------------------------------------------------------------------------
    
    .

    Comment


    • #3
      Thank you Andrew. This worked.

      Comment

      Working...
      X