Announcement

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

  • Linear Models With Many Levels of Fixed Effects( REGHDFE)

    Dear Stata Members

    I ran the following panel regression with firm fixed effects(in my case, xtset id year; where id denotes individual firms) and year dummies, and standard errors clustered at firm level

    Code:
    xtreg cash_ta2_w epu ///
    tra_cre2_w inven_ta_w ///
    size_w fixed_ass_w lever_w ltbankborr2_w stbankborr2_w rd_ta_w div_w ///
    sgrowth_w oppro_ta_w mb_w  ///
    fcfvol icfvol fsalvol isalvol ///
    realinterestrate gdpgrowthannual ///
    i.year, fe vce(robust)
    Now I want standard errors to be clustered by both firm and year to control for the possibility that standard errors are correlated across firms and over time.

    I ran the following code
    Code:
    reghdfe cash_ta2_w epu ///
    tra_cre2_w inven_ta_w ///
    size_w fixed_ass_w lever_w ltbankborr2_w stbankborr2_w rd_ta_w div_w ///
    sgrowth_w oppro_ta_w mb_w  ///
    fcfvol icfvol fsalvol isalvol ///
    realinterestrate gdpgrowthannual ///
    i.year, absorb(id) vce(cluster id year)
    Did I run the right code?

    References
    HTML Code:
    http://scorreia.com/software/reghdfe/

  • #2
    Ial:
    your code seems correct.
    Obviously, it would have been interesting to see, in addition:
    -how you -xtset- your data before -xtreg-;
    - the output of both codes that Stata gave you back.
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      Dear Carlo
      Thanks for your prompt reply and guidance
      how you -xtset- your data before -xtreg-;
      Code:
      encode companyname,gen(id)           //companyname denotes name of individual firms
      xtset id year


      Code:
      . xtreg cash_ta2_w epu ///
      > tra_cre2_w inven_ta_w ///
      > size_w fixed_ass_w lever_w ltbankborr2_w stbankborr2_w rd_ta_w div_w ///
      > sgrowth_w oppro_ta_w mb_w  ///
      > fcfvol icfvol fsalvol isalvol ///
      > realinterestrate gdpgrowthannual ///
      > i.year, fe vce(robust)
      note: 2008.year omitted because of collinearity
      note: 2010.year omitted because of collinearity
      note: 2012.year omitted because of collinearity
      
      Fixed-effects (within) regression               Number of obs      =     23488
      Group variable: id                              Number of groups   =      2773
      
      R-sq:  within  = 0.1466                         Obs per group: min =         1
             between = 0.1991                                        avg =       8.5
             overall = 0.1990                                        max =        15
      
                                                      F(30,2772)         =     20.62
      corr(u_i, Xb)  = -0.0981                        Prob > F           =    0.0000
      
                                            (Std. Err. adjusted for 2773 clusters in id)
      ----------------------------------------------------------------------------------
                       |               Robust
            cash_ta2_w |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
      -----------------+----------------------------------------------------------------
                   epu |   .0149305   .0024643     6.06   0.000     .0100985    .0197625
            tra_cre2_w |  -.1257609   .0098413   -12.78   0.000    -.1450578   -.1064639
            inven_ta_w |  -.2111026   .0137582   -15.34   0.000    -.2380801   -.1841252
                size_w |   -.001439   .0019053    -0.76   0.450    -.0051748    .0022969
           fixed_ass_w |  -.1758122   .0103571   -16.97   0.000    -.1961207   -.1555037
               lever_w |   .0056474   .0076046     0.74   0.458    -.0092639    .0205587
         ltbankborr2_w |  -.0241265   .0086593    -2.79   0.005    -.0411058   -.0071471
         stbankborr2_w |  -.0186561   .0092892    -2.01   0.045    -.0368705   -.0004416
               rd_ta_w |  -.0865674   .1515961    -0.57   0.568    -.3838202    .2106854
                 div_w |   .4987488   .0830426     6.01   0.000     .3359171    .6615805
             sgrowth_w |  -.0014762   .0017478    -0.84   0.398    -.0049034     .001951
            oppro_ta_w |   .0958302   .0123161     7.78   0.000     .0716804    .1199799
                  mb_w |   .0054963   .0011377     4.83   0.000     .0032656     .007727
                fcfvol |   .0104895   .0116456     0.90   0.368    -.0123455    .0333244
                icfvol |   .0352893   .0405422     0.87   0.384    -.0442067    .1147852
               fsalvol |   .0085543   .0042196     2.03   0.043     .0002804    .0168281
               isalvol |  -.0106887    .009929    -1.08   0.282    -.0301577    .0087803
      realinterestrate |   .0006745   .0003318     2.03   0.042     .0000239    .0013252
       gdpgrowthannual |  -.0001855   .0003541    -0.52   0.600    -.0008798    .0005089
                       |
                  year |
                 2006  |   .0105316   .0018659     5.64   0.000     .0068728    .0141903
                 2007  |   .0084752   .0021651     3.91   0.000     .0042297    .0127207
                 2008  |          0  (omitted)
                 2009  |  -.0088026   .0021055    -4.18   0.000    -.0129312    -.004674
                 2010  |          0  (omitted)
                 2011  |    .007997   .0014722     5.43   0.000     .0051102    .0108838
                 2012  |          0  (omitted)
                 2013  |  -.0029671   .0015151    -1.96   0.050     -.005938    3.84e-06
                 2014  |   .0005053   .0027044     0.19   0.852    -.0047974    .0058081
                 2015  |   .0022666   .0033117     0.68   0.494    -.0042272    .0087603
                 2016  |   .0056691   .0035223     1.61   0.108    -.0012375    .0125757
                 2017  |   .0045639   .0032355     1.41   0.158    -.0017804    .0109081
                 2018  |   .0047014   .0033819     1.39   0.165    -.0019298    .0113327
                 2019  |   .0037849   .0039063     0.97   0.333    -.0038747    .0114446
                       |
                 _cons |   .0866509   .0167529     5.17   0.000     .0538015    .1195004
      -----------------+----------------------------------------------------------------
               sigma_u |  .06773354
               sigma_e |  .05018485
                   rho |  .64559608   (fraction of variance due to u_i)
      ----------------------------------------------------------------------------------

      Code:
      . reghdfe cash_ta2_w epu ///
      > tra_cre2_w inven_ta_w ///
      > size_w fixed_ass_w lever_w ltbankborr2_w stbankborr2_w rd_ta_w div_w ///
      > sgrowth_w oppro_ta_w mb_w  ///
      > fcfvol icfvol fsalvol isalvol ///
      > realinterestrate gdpgrowthannual ///
      > ,absorb(id) vce(cluster id year)
      (dropped 278 singleton observations)
      (MWFE estimator converged in 1 iterations)
      
      HDFE Linear regression                            Number of obs   =     23,210
      Absorbing 1 HDFE group                            F(  19,     14) =      27.63
      Statistics robust to heteroskedasticity           Prob > F        =     0.0000
                                                        R-squared       =     0.6337
                                                        Adj R-squared   =     0.5892
      Number of clusters (id)      =      2,495         Within R-sq.    =     0.1427
      Number of clusters (year)    =         15         Root MSE        =     0.0503
      
                                         (Std. Err. adjusted for 15 clusters in id year)
      ----------------------------------------------------------------------------------
                       |               Robust
            cash_ta2_w |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
      -----------------+----------------------------------------------------------------
                   epu |   .0063721   .0024511     2.60   0.021      .001115    .0116292
            tra_cre2_w |  -.1244352   .0096545   -12.89   0.000     -.145142   -.1037284
            inven_ta_w |  -.2085149   .0152315   -13.69   0.000    -.2411832   -.1758466
                size_w |  -.0002334   .0016184    -0.14   0.887    -.0037045    .0032377
           fixed_ass_w |  -.1780021   .0120293   -14.80   0.000    -.2038024   -.1522017
               lever_w |    .005923   .0082606     0.72   0.485    -.0117943    .0236403
         ltbankborr2_w |  -.0255102   .0087729    -2.91   0.011    -.0443261   -.0066942
         stbankborr2_w |  -.0189028   .0095001    -1.99   0.067    -.0392785    .0014728
               rd_ta_w |   -.077844   .1464953    -0.53   0.603    -.3920452    .2363573
                 div_w |   .5102609   .0971987     5.25   0.000     .3017903    .7187315
             sgrowth_w |  -.0009679   .0022725    -0.43   0.677     -.005842    .0039062
            oppro_ta_w |   .0922582    .011566     7.98   0.000     .0674516    .1170648
                  mb_w |   .0057251   .0012024     4.76   0.000     .0031462     .008304
                fcfvol |    .010845   .0127056     0.85   0.408    -.0164059    .0380958
                icfvol |   .0357164   .0421566     0.85   0.411    -.0547006    .1261333
               fsalvol |   .0089683   .0062749     1.43   0.175    -.0044901    .0224266
               isalvol |   -.004646   .0091316    -0.51   0.619    -.0242314    .0149393
      realinterestrate |   .0002678   .0004508     0.59   0.562    -.0006991    .0012347
      gdpgrowthannual |   -.000237    .000705    -0.34   0.742     -.001749     .001275
                 _cons |   .1161762   .0191768     6.06   0.000      .075046    .1573064
      ----------------------------------------------------------------------------------
      
      Absorbed degrees of freedom:
      -----------------------------------------------------+
       Absorbed FE | Categories  - Redundant  = Num. Coefs |
      -------------+---------------------------------------|
                id |      2495        2495           0    *|
      -----------------------------------------------------+
      * = FE nested within cluster; treated as redundant for DoF computation

      However, if I put absorb(year id), I will get the results below

      Code:
      . reghdfe cash_ta2_w epu ///
      > tra_cre2_w inven_ta_w ///
      > size_w fixed_ass_w lever_w ltbankborr2_w stbankborr2_w rd_ta_w div_w ///
      > sgrowth_w oppro_ta_w mb_w  ///
      > fcfvol icfvol fsalvol isalvol ///
      > realinterestrate gdpgrowthannual ///
      > ,absorb(id year) vce(cluster id year)
      (dropped 278 singleton observations)
      note: epu is probably collinear with the fixed effects (all partialled-out values are close to zero; tol = 1.0e-09)
      note: realinterestrate is probably collinear with the fixed effects (all partialled-out values are close to zero; tol = 1.0
      > e-09)
      note: gdpgrowthannual is probably collinear with the fixed effects (all partialled-out values are close to zero; tol = 1.0e
      > -09)
      (MWFE estimator converged in 7 iterations)
      Warning: VCV matrix was non-positive semi-definite; adjustment from Cameron, Gelbach & Miller applied.
      note: epu omitted because of collinearity
      note: realinterestrate omitted because of collinearity
      note: gdpgrowthannual omitted because of collinearity
      
      HDFE Linear regression                            Number of obs   =     23,210
      Absorbing 2 HDFE groups                           F(  16,     14) =      28.78
      Statistics robust to heteroskedasticity           Prob > F        =     0.0000
                                                        R-squared       =     0.6353
                                                        Adj R-squared   =     0.5908
      Number of clusters (id)      =      2,495         Within R-sq.    =     0.1395
      Number of clusters (year)    =         15         Root MSE        =     0.0502
      
                                         (Std. Err. adjusted for 15 clusters in id year)
      ----------------------------------------------------------------------------------
                       |               Robust
            cash_ta2_w |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
      -----------------+----------------------------------------------------------------
                   epu |          0  (omitted)
            tra_cre2_w |  -.1257609   .0094913   -13.25   0.000    -.1461176   -.1054041
            inven_ta_w |  -.2111026   .0152594   -13.83   0.000    -.2438309   -.1783744
                size_w |   -.001439   .0022175    -0.65   0.527     -.006195    .0033171
           fixed_ass_w |  -.1758122   .0123278   -14.26   0.000    -.2022526   -.1493717
               lever_w |   .0056474   .0082831     0.68   0.506    -.0121181    .0234128
         ltbankborr2_w |  -.0241265   .0090278    -2.67   0.018    -.0434891   -.0047638
         stbankborr2_w |  -.0186561   .0096456    -1.93   0.074    -.0393438    .0020317
               rd_ta_w |  -.0865674   .1450336    -0.60   0.560    -.3976335    .2244986
                 div_w |   .4987488   .1003184     4.97   0.000     .2835872    .7139104
             sgrowth_w |  -.0014762   .0024878    -0.59   0.562     -.006812    .0038596
            oppro_ta_w |   .0958302   .0111398     8.60   0.000     .0719376    .1197228
                  mb_w |   .0054963   .0011677     4.71   0.000     .0029919    .0080007
                fcfvol |   .0104895   .0122686     0.85   0.407     -.015824     .036803
                icfvol |   .0352893   .0451034     0.78   0.447    -.0614479    .1320265
               fsalvol |   .0085543   .0061449     1.39   0.186    -.0046253    .0217339
               isalvol |  -.0106887   .0091993    -1.16   0.265    -.0304192    .0090419
      realinterestrate |          0  (omitted)
       gdpgrowthannual |          0  (omitted)
                 _cons |   .1578272   .0178302     8.85   0.000     .1195852    .1960693
      ----------------------------------------------------------------------------------
      
      Absorbed degrees of freedom:
      -----------------------------------------------------+
       Absorbed FE | Categories  - Redundant  = Num. Coefs |
      -------------+---------------------------------------|
                id |      2495        2495           0    *|
              year |        15          15           0    *|
      -----------------------------------------------------+
      * = FE nested within cluster; treated as redundant for DoF computation
      .

      Variables realinterestrate gdpgrowthannual & epu are same for all firms for a particular year as they are macro in nature (cross-sectionally invariant). I suspect that could be the reason why epu, realinterestrate & gdpgrowthannual got omitted when I put year inside the absorb.
      Last edited by lal mohan kumar; 03 Oct 2020, 04:31.

      Comment


      • #4
        Ial:
        thanks for clarifying.
        I would stop at -abs(id)- with standard errors clustered on both -id- and -year-.
        Kind regards,
        Carlo
        (Stata 19.0)

        Comment


        • #5
          Thanks Carlo

          Comment

          Working...
          X