Announcement

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

  • Advice on running fixed effect model controlling for year and industry

    I want to run a fixed effect model controlling for year and industry effects. I have read through some references on how to go about it, but yet not really sure if the procedures I am following are right

    First, I would need to xtset my panel data with industry grouping. But I am not sure if I group data using Ticker/firrm id is okay too

    Code:
    egen id = group(Industry)
    
    xtset id Year, y
    The next I am confused which following to run as some references says to add Stata features xi: before running fixed effect model on panel data

    Methord 1

    Code:
    xtreg DACC ROA Size MTB LEV LOSS i.Year, fe
    Methord 2

    Code:
    xi: xtreg DACC ROA Size MTB LEV LOSS i.Year, fe
    Lastly, run command to see if time fixed effects are needed

    Code:
     testparm i.year 
    Below is my data in panel structure

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str9 Ticker int Year str23 Industry byte SICCode float(ROA Size MTB LEV LOSS DACC)
    "TH:SPSU"   2007 "Industrials"             11   .014094287  14.58573  .4777623  -.04100476 0   -.13350403
    "TH:GC"     2012 "Industrials"             11    .06899457  13.93367  .8494591           0 0   .030991036
    "TH:TPCH"   2012 "Resources"               33 -.0020756533  11.93638         . .0002619121 1            .
    "TH:EE"     2014 "Agro & Food Industry"    22 .00018812453  14.25858  2.487009 .0023916855 0    .05917667
    "TH:TTL"    2014 "Consumer Products"       66    -.2715816 14.133175 1.5325614   .00266392 1    -.1782501
    "TH:EE"     2011 "Agro & Food Industry"    22  -.006340273 14.210468  1.240886 .0038401396 1   .015338974
    "TH:EE"     2013 "Agro & Food Industry"    22   .007601305 14.259856   1.34223  .003901328 0   .017898992
    "TH:CSR"    2000 "Services"                55   .008508377 14.677366 .12823841  .004070032 0     .1108473
    "TH:CSR"    2001 "Services"                55   .012657777  14.68637 .17238885  .004446275 0    .04925008
    "TH:CSR"    2002 "Services"                55   .017517675 14.697324  .2813456 .0044545652 0     .0520633
    "TH:CSR"    2003 "Services"                55   .016676517 14.698357  .3215286 .0045120073 0    .04526159
    "TH:EE"     2012 "Agro & Food Industry"    22    .04046876 14.252687 2.1824718  .004553293 0   .066115335
    "TH:CSR"    1998 "Services"                55   .010474646 14.285906  .2188438  .005102376 0    .05515802
    "TH:CSR"    1999 "Services"                55   .010221212  14.29216  .2686679  .005165552 0     .0815233
    "TH:CSR"    2008 "Services"                55   .029514614 14.471094  .4226215  .005320657 0   -.02775518
    "TH:CSR"    2004 "Services"                55   .019360255 14.700903  .3890025  .005347091 0    .04013493
    "TH:EE"     2010 "Agro & Food Industry"    22    -.0299568 14.219323 2.4644845  .005696073 1    .02374406
    "TH:CSR"    1995 "Services"                55   .010037953 14.220117 .28630632  .006270718 0    .02764596
    "TH:CSR"    2005 "Services"                55    .02462999  14.70609  .3725338  .006273235 0    .04560977
    "TH:CSR"    1997 "Services"                55    .00933447 14.296027  .3062665   .00647284 0     .1511482
    "TH:EE"     2009 "Agro & Food Industry"    22   -.07361579 14.250206  2.899881  .006887054 1   -.05890745
    "TH:CSR"    2006 "Services"                55    .02740221 14.673937   .437736  .007565762 0    .04198445
    "TH:CSR"    2007 "Services"                55    .03638902 14.472492  .4850081  .008483323 0    .01137247
    "TH:CSR"    2010 "Services"                55    .03227611  14.42795  .5435546  .008543436 0    .03366521
    "TH:GREEN"  2010 "Resources"               33   -.08444518  13.22606  .3865738  .008890579 1  -.067248516
    "TH:CSR"    2009 "Services"                55    .03392785 14.416633 .58970714  .009038656 0    .04010501
    "TH:CSR"    2011 "Services"                55   .022481415 14.432555  .4915923  .010028908 0    .02457018
    "TH:CSR"    2012 "Services"                55   .036740415  14.37295  .5702619  .011839443 0   .008430988
    "TH:FANCY"  2008 "Consumer Products"       66  -.002275843  14.20212  .4007641  .012065365 1  -.029234566
    "TH:FANCY"  2012 "Consumer Products"       66   -.05364843 14.061686  .6559972  .014183925 1   -.05211401
    "TH:BSBM"   2014 "Industrials"             11   .005101281  14.44726  .7634732  .014200117 0    .02556101
    "TH:FANCY"  2011 "Consumer Products"       66  -.024740083  14.11579   .667412  .014276002 1   .017903345
    "TH:GREEN"  2007 "Resources"               33   .014111684 13.316074  .9278563   .01436874 0   .071650654
    "TH:CSR"    1996 "Services"                55  -.007614495  14.32066 .23859185  .014927885 1    .03803191
    "TH:NUSA"   2009 "Property & Construction" 77  -.063287064 12.200255 1.3596687  .014996982 1    .51596266
    "TH:ESTAR"  2004 "Property & Construction" 77   .023478456 15.229934 .59103405  .016378747 0     .2145841
    "TH:THL"    1997 "Resources"               33  -.026333883 13.660789 .24226014  .017023228 1    .07399729
    "TH:FANCY"  2010 "Consumer Products"       66    .03932139 14.175484  .6812707  .018084953 0   -.08507758
    "TH:CITY"   2009 "Industrials"             11    .09795809 13.618333 .55446744  .018106194 0   -.08706427
    "TH:GREEN"  2008 "Resources"               33   .010875948  13.31223  .3286618  .018575953 0   -.10521555
    "TH:GREEN"  2011 "Resources"               33    -.1208288 13.110133  .3045941  .019580014 1    .02429825
    "TH:MAX"    2014 "Agro & Food Industry"    22  -.012943343  13.77311 13.087386   .01972279 1   -.10308635
    "TH:GREEN"  2009 "Resources"               33   .002910374 13.319901   .385308  .020149376 0   -.02801403
    "TH:THL"    1996 "Resources"               33  .0031028066 13.689335 .45175385  .020599913 0    .04710346
    "TH:FANCY"  2014 "Consumer Products"       66   .015741581  14.06943   .752555  .021333985 0    .06809422
    "TH:CITY"   2013 "Industrials"             11     .1124619  13.92324  .8257934  .021445643 0  -.006409266
    "TH:BROCK"  2011 "Property & Construction" 77   .010353744 14.031117   .692175  .021804526 0   -.01194092
    "TH:BROCK"  2012 "Property & Construction" 77    .02430121  14.04804 1.0046791  .021842003 0   -.04838569
    "TH:TSTE"   2005 "Services"                55    .04087449  13.88498  .4739544  .022144897 0   .023569893
    "TH:BROCK"  2010 "Property & Construction" 77   .011040293  14.03121  .7512964  .023772333 0   -.06749149
    "TH:MANRIN" 2010 "Services"                55    .09554751 13.346224  .4891901   .02389487 0    .05745332
    "TH:ESTAR"  2008 "Property & Construction" 77    .02516061  15.26544  .3088253  .024305776 0    -.1190804
    "TH:CITY"   2010 "Industrials"             11    .07490723 13.666142  .7111215  .025234194 0    .06643253
    "TH:TH"     2012 "Services"                55    .02724144 12.925256  4.993073  .025324503 0    .08167597
    "TH:SST"    1998 "Agro & Food Industry"    22    .01872324 12.972658  .4327315   .02566896 0 -.0011186806
    "TH:TH"     2005 "Services"                55    .02668001 11.897432  .9901683  .026434926 0  -.003942776
    "TH:PRIME"  2007 "Resources"               33   -.25100282  12.80208 2.3704576   .02659985 1    -.1731891
    "TH:BROCK"  2014 "Property & Construction" 77   .009595572 14.050385 1.8651003  .026659023 0   -.05020552
    "TH:BROCK"  2009 "Property & Construction" 77   .014665804 14.035526  .5113254   .02693292 0    .09961533
    "TH:SUPER"  2013 "Resources"               33     .0835338 13.519955  3.961224  .027229553 0     .3377129
    "TH:ESTAR"  2009 "Property & Construction" 77   .005035982 15.273445   .381608   .02761785 0   .009397772
    "TH:BROCK"  2013 "Property & Construction" 77  -.012355656 14.042366 1.1352468  .028494047 1   -.02570643
    "TH:FANCY"  2013 "Consumer Products"       66   .020482384  14.09883  .6306444   .02878652 0    .06619368
    "TH:FANCY"  2009 "Consumer Products"       66    .05592462 14.225496  .7258965   .02887053 0  -.007587069
    "TH:AI"     2004 "Resources"               33    .18728033 14.297224 4.2949805   .02918375 0   -.10123187
    "TH:TSTE"   2004 "Services"                55    .05979726 13.869002  .7465113  .029244095 0    .03331303
    "TH:UPOIC"  2002 "Agro & Food Industry"    22    .06390125 13.508128 1.7738768  .031169387 0  .0021835372
    "TH:MANRIN" 2002 "Services"                55    .06497018 13.248763   .840821     .031558 0    .02312358
    "TH:CFRESH" 2009 "Agro & Food Industry"    22    .12792502 14.174372 1.1547698  .031629577 0   -.07600099
    "TH:TH"     2007 "Services"                55 -.0018997847 11.890032  .6124228   .03241979 1    .07279292
    "TH:MANRIN" 2007 "Services"                55   .025828796 13.326117  .8162632  .032711364 0   .025271904
    "TH:FANCY"  2007 "Consumer Products"       66    .02627013 14.226185  .6320099   .03333391 0    -.0577042
    "TH:THL"    1995 "Resources"               33   .013611668  13.73223  .6076633   .03417372 0   .000791589
    "TH:TH"     2009 "Services"                55  -.002619219   11.8903  .6817165   .03444753 1    .06828755
    "TH:TH"     2008 "Services"                55   .003706535 11.894767  .6790115  .034921978 0    .12491308
    "TH:MANRIN" 2011 "Services"                55   -.03799874  13.28389 .47471395  .035524487 1   .032001007
    "TH:BROCK"  2008 "Property & Construction" 77    .06539111 14.066417  .3550506  .035737906 0   -.14796616
    "TH:BROCK"  2006 "Property & Construction" 77    .03812097 13.986418  .9880153  .035969894 0    -.4165837
    "TH:ACC"    2013 "Resources"               33   .063474126  13.53639  1.285913   .03597594 0   -.17010236
    "TH:MANRIN" 2001 "Services"                55    .09485351 13.266666  .7510354  .036446296 0    .10605314
    "TH:TTL"    2013 "Consumer Products"       66    .04614244 14.424273   .773465   .03727758 0   -.13896605
    "TH:SST"    2003 "Agro & Food Industry"    22    .06153486 13.217994  .8110731   .03738622 0    .14343196
    "TH:TSTE"   1997 "Services"                55    .14295185 12.848227         .   .03742298 0    .13269389
    "TH:TH"     2010 "Services"                55 .00008161378  11.89842  .8241841   .03748113 0   -.09472122
    "TH:MANRIN" 2004 "Services"                55    .04591553  13.30616  .6469458   .03791901 0  .0043247337
    "TH:RWI"    2010 "Industrials"             11    .03927566  13.23513         .   .03825545 0    -.1099177
    "TH:ACC"    2014 "Resources"               33   .011469268  13.51036 1.1477786   .03838602 0            .
    "TH:SST"    2002 "Agro & Food Industry"    22    .05623237  13.19954   .652477   .03862874 0    .05832521
    "TH:CITY"   2006 "Industrials"             11    .18833555  13.42103 1.0002177   .03882907 0    .01367529
    "TH:UPOIC"  2001 "Agro & Food Industry"    22     .1261874 13.623796 1.7563664   .03899378 0   -.07932497
    "TH:CITY"   2011 "Industrials"             11     .0856399 13.752286  .6785945   .03927528 0  -.068395935
    "TH:GREEN"  2006 "Resources"               33    .12532954  13.40116 1.2430297   .03951602 0    .12175868
    "TH:CITY"   2012 "Industrials"             11    .13172463  13.86745  .9200115   .04030529 0   -.10071439
    "TH:MANRIN" 2005 "Services"                55    .07761973 13.354243  .6799977   .04041657 0    .04470363
    "TH:MANRIN" 2003 "Services"                55     .0770766 13.302565  .7287181   .04195387 0     .0433143
    "TH:TR"     2009 "Consumer Products"       66   .028913254 16.588186  .4736879   .04249008 0  -.022260224
    "TH:TR"     2001 "Consumer Products"       66    .10832603  15.53708  .4141641   .04271182 0     .0465218
    "TH:GREEN"  2014 "Resources"               33   -.27074698 12.623858  9.593626   .04274346 1   -.17125164
    "TH:CITY"   2014 "Industrials"             11    .11920575 14.035776  .9363398   .04375213 0   -.10432828
    "TH:TSTE"   1998 "Services"                55    .06311437  12.78541  .6154369   .04412123 0    .08939533
    end
    format %ty Year

  • #2
    The people who use method 2 are still in 2010, so don't listen to them. The method you wanna go with is the first one.

    Edit: with the usual disclaimers about using two way fixed effect models.
    Last edited by Jared Greathouse; 17 Apr 2022, 17:24.

    Comment


    • #3
      Jared GreathouseThank your Jared for your useful advice as usual.

      I have two following questions, just to understand the mechanics of it - would be really helpful to get your insight on or any other resources

      So, I should always group variable(s) (i.e. industry/firm or industry firm) that I am interested to run the fixed effect on. So for example, if I was interested to control for firm (i.e coded as Ticker) specific characteristics, I should have done

      Code:
       egen id = group(Ticker) 
       xtset id Year, y
      Secondly, putting in the argument fe is the same as putting i.Industry

      Code:
       
       xtreg DACC ROA Size MTB LEV LOSS i.Year, fe
      The above code is same putting indicator variable instead of fe argument

      Code:
       
       xtreg DACC ROA Size MTB LEV LOSS i.Year i.Industry
      Not sure if my intuition is right. Thank you once again

      Comment


      • #4
        Farhan:
        not quite.
        Starting from:
        Code:
         egen id = group(Ticker)  
         xtset id Year, y
        you can go -fe- with -xtreg.fe- (this is the approach that I would follow):
        Code:
         
         xtreg DACC ROA Size MTB LEV LOSS i.Year, fe vce(cluster clusterid)
        or you can go -fe- via -regress- (no need to -xtset- your dataset in this case):

        Code:
        regress DACC ROA Size MTB LEV LOSS i.Ticker i.Year, vce(cluster clusterid)
        Your last code calls in fact -xtreg, re., as the -re- specifucation is the -xtreg- default mode.
        Kind regards,
        Carlo
        (StataNow 18.5)

        Comment


        • #5
          Carlo Lazzaro Thank you for you advice and extending my knowledge on FE models. I have looked into cluster analysis and get the essence behind the using the command here

          Comment


          • #6
            Farhan:
            Fred:
            please find two links to the same reference about clustered standard errors:
            1)
            http://cameron.econ.ucdavis.edu/rese...5_February.pdf
            2) http://jhr.uwpress.org/content/50/2/317.short
            Kind regards,
            Carlo
            (StataNow 18.5)

            Comment


            • #7
              I ran the following regressions and I am fully aware might be wrong. I have id variable in my data which is the grouped by Ticker (I used that when cleaning, sorting and running other regressions). However, since I want to control for industry fixed effects, following earlier comments I tried to form id2 grouped by Industry - but thrown with error when I try to xtset the data

              Please note I have a variable in my data SICCode- which is basically numerical coding since Industry is a string variable

              Code:
              egen id2 = group(Industry)
              xtset id2 Year, y
              repeated time values within panel
              r(451);
              Anyway, I went ahead to test out the regression to understand mechanics of it- where I xtset data using id variable grouped by Ticker and likewise fixed effect at firm level was picked I believe instead of Industry

              First regression method:

              Code:
              xtset id Year, y
              
              Panel variable: id (strongly balanced)
               Time variable: Year, 1995 to 2014
                       Delta: 1 year
              
              xtreg DACC ROA Size MTB LEV LOSS i.Year, fe
              
              Fixed-effects (within) regression               Number of obs     =      6,091
              Group variable: id                              Number of groups  =        528
              
              R-squared:                                      Obs per group:
                   Within  = 0.7144                                         min =          1
                   Between = 0.4957                                         avg =       11.5
                   Overall = 0.6909                                         max =         20
              
                                                              F(24,5539)        =     577.41
              corr(u_i, Xb) = -0.1063                         Prob > F          =     0.0000
              
              ------------------------------------------------------------------------------
                      DACC | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
              -------------+----------------------------------------------------------------
                       ROA |   .6401016   .0054889   116.62   0.000     .6293412    .6508619
                      Size |    .038937   .0088432     4.40   0.000     .0216008    .0562731
                       MTB |   .0003609   .0002078     1.74   0.082    -.0000464    .0007683
                       LEV |   .0346429   .0059425     5.83   0.000     .0229933    .0462924
                      LOSS |   .0074047   .0104997     0.71   0.481    -.0131788    .0279883
                           |
                      Year |
                     1996  |   .0016526    .029886     0.06   0.956    -.0569356    .0602409
                     1997  |   .0469281   .0300176     1.56   0.118    -.0119181    .1057743
                     1998  |  -.0114191   .0291586    -0.39   0.695    -.0685814    .0457433
                     1999  |   .0107773   .0295857     0.36   0.716    -.0472223    .0687769
                     2000  |   .0260907   .0293926     0.89   0.375    -.0315303    .0837116
                     2001  |  -.0178249   .0276522    -0.64   0.519    -.0720341    .0363843
                     2002  |  -.1813733   .0274959    -6.60   0.000     -.235276   -.1274706
                     2003  |    -.01713   .0271839    -0.63   0.529    -.0704212    .0361612
                     2004  |  -.0221002   .0268507    -0.82   0.411    -.0747382    .0305378
                     2005  |  -.0244461   .0265148    -0.92   0.357    -.0764254    .0275333
                     2006  |    -.02022   .0264784    -0.76   0.445    -.0721282    .0316881
                     2007  |  -.0083642   .0264438    -0.32   0.752    -.0602043     .043476
                     2008  |  -.0266679   .0264223    -1.01   0.313    -.0784659    .0251302
                     2009  |  -.0165806   .0264107    -0.63   0.530     -.068356    .0351948
                     2010  |  -.0374606   .0264728    -1.42   0.157    -.0893577    .0144366
                     2011  |  -.0175649    .026584    -0.66   0.509      -.06968    .0345501
                     2012  |  -.0221275   .0266933    -0.83   0.407     -.074457    .0302019
                     2013  |  -.0249732   .0270992    -0.92   0.357    -.0780984    .0281519
                     2014  |  -.0409506   .0274826    -1.49   0.136    -.0948273    .0129262
                           |
                     _cons |  -.6167919   .1317045    -4.68   0.000    -.8749845   -.3585993
              -------------+----------------------------------------------------------------
                   sigma_u |  .15568554
                   sigma_e |  .26735488
                       rho |  .25322653   (fraction of variance due to u_i)
              ------------------------------------------------------------------------------
              F test that all u_i=0: F(527, 5539) = 1.62                   Prob > F = 0.0000
              
              testparm i.Year
              
               ( 1)  1996.Year = 0
               ( 2)  1997.Year = 0
               ( 3)  1998.Year = 0
               ( 4)  1999.Year = 0
               ( 5)  2000.Year = 0
               ( 6)  2001.Year = 0
               ( 7)  2002.Year = 0
               ( 8)  2003.Year = 0
               ( 9)  2004.Year = 0
               (10)  2005.Year = 0
               (11)  2006.Year = 0
               (12)  2007.Year = 0
               (13)  2008.Year = 0
               (14)  2009.Year = 0
               (15)  2010.Year = 0
               (16)  2011.Year = 0
               (17)  2012.Year = 0
               (18)  2013.Year = 0
               (19)  2014.Year = 0
              
                     F( 19,  5539) =    6.21
                          Prob > F =    0.0000

              Second regression method 2:


              Code:
               regress DACC ROA Size MTB LEV LOSS i.SICCode i.Year, vce(cluster id)
              
              Linear regression                               Number of obs     =      6,091
                                                              F(30, 527)        =      34.03
                                                              Prob > F          =     0.0000
                                                              R-squared         =     0.6967
                                                              Root MSE          =     .27407
              
                                                 (Std. err. adjusted for 528 clusters in id)
              ------------------------------------------------------------------------------
                           |               Robust
                      DACC | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
              -------------+----------------------------------------------------------------
                       ROA |   .6304195   .0405184    15.56   0.000     .5508221    .7100169
                      Size |   .0179765   .0039318     4.57   0.000     .0102526    .0257003
                       MTB |   .0001491   .0001746     0.85   0.393    -.0001939    .0004921
                       LEV |   .0409664   .0329415     1.24   0.214    -.0237463    .1056791
                      LOSS |   .0206045   .0103923     1.98   0.048     .0001891    .0410199
                           |
                   SICCode |
                       22  |  -.0041235   .0145793    -0.28   0.777    -.0327641    .0245171
                       33  |  -.0182999   .0182552    -1.00   0.317    -.0541619    .0175621
                       44  |  -.0195803    .014036    -1.40   0.164    -.0471536    .0079931
                       55  |  -.0006888   .0092429    -0.07   0.941    -.0188463    .0174687
                       66  |   .0217312   .0081192     2.68   0.008     .0057812    .0376813
                       77  |  -.0363604   .0140163    -2.59   0.010    -.0638951   -.0088256
                           |
                      Year |
                     1996  |   .0038867   .0089561     0.43   0.664    -.0137072    .0214807
                     1997  |   .0391513   .0142677     2.74   0.006     .0111229    .0671798
                     1998  |   -.015147   .0112009    -1.35   0.177    -.0371509     .006857
                     1999  |     .00445   .0114109     0.39   0.697    -.0179664    .0268664
                     2000  |   .0060156   .0106625     0.56   0.573    -.0149305    .0269618
                     2001  |  -.0210449   .0128656    -1.64   0.102     -.046319    .0042292
                     2002  |  -.1853722   .0452815    -4.09   0.000    -.2743265   -.0964179
                     2003  |  -.0204993   .0120276    -1.70   0.089    -.0441274    .0031287
                     2004  |  -.0174669   .0119117    -1.47   0.143    -.0408672    .0059334
                     2005  |  -.0170047   .0353712    -0.48   0.631    -.0864906    .0524811
                     2006  |  -.0172031   .0185462    -0.93   0.354    -.0536366    .0192303
                     2007  |   .0033796   .0114736     0.29   0.768    -.0191599    .0259191
                     2008  |  -.0189758   .0141154    -1.34   0.179    -.0467051    .0087536
                     2009  |  -.0055381   .0112587    -0.49   0.623    -.0276555    .0165793
                     2010  |  -.0239323   .0138993    -1.72   0.086    -.0512372    .0033725
                     2011  |  -4.04e-06   .0105676    -0.00   1.000    -.0207638    .0207557
                     2012  |  -.0008115   .0130941    -0.06   0.951    -.0265344    .0249115
                     2013  |   .0001275   .0113703     0.01   0.991    -.0222092    .0224641
                     2014  |   -.011693   .0131433    -0.89   0.374    -.0375127    .0141268
                           |
                     _cons |  -.3071289   .0531258    -5.78   0.000    -.4114932   -.2027647
              ------------------------------------------------------------------------------
              Any advice would be really helpful

              Comment


              • #8
                Farhan:
                1) controlling for -i.industry- in -xtreg,fe- usually is wasting your time, as -panelid- (ie, firms) rarely change -industry- as time goes by (hence, as expected, the -fe- estimator will wipe out -industry-, as it is a time-invariant variable).
                2) stick with your first -xtreg, fe- code (the within R-sq is good);
                3) replace default standard errors with their cluster-robust counterparts (ie, use the -robust- or -vce(cluster panelid iptions; the do the very saem job under -xtreg-).
                Kind regards,
                Carlo
                (StataNow 18.5)

                Comment


                • #9
                  Carlo Lazzaro Thank you Carlo for reviewing my work and providing such useful advice. I understood the intuition behind your thought

                  Comment

                  Working...
                  X