Announcement

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

  • Time Fixed-Effects [xtreg,fe vs. reghdfe]

    I have a question about diff-in-diff results with different commands.

    x1 is the time-variant binary variable, if it is before the treatment it's 0, if its after the treatment its 1.

    Code:
    1. 
    xtreg y i.x1##i.x2 i.date, fe robust 
    
    gen treat = (x1 == 1 & x2 == 1)
    
    2. 
    xtdidreg (y) (treat), group(id) time(date) 
    
    3. 
    reghdfe y i.x1##i.x2, absorb(id date) vce(robust)

    The first two diff-in-diff regression commands give me exactly same results in terms of ATET and i.x1#i.x2.

    However, with xtreg, "i.x1" is not omitted, and this sounds a little awkward, since I have controlled for the time-fixed effect in the first command.

    When I run the same diff-in-diff with reghdfe, only the interaction term is left, and non-interacted terms are omitted as expected.

    So my question is, why is command using
    Code:
     xtreg y i.x1##i.x2 i.date, fe robust
    returning some value for i.x1? (which is totally unexpected, considering its original value when estimated solely e.g. xtreg i.x1, fe robust)

    Thank you.


  • #2
    These commands are likely doing different things under the hood as far as presentation goes- but if the ATT is the same, I don't see why it matters very much.



    You don't give your example data/the results, so I can't comment further, but that's likely the issue.

    EDIT: Nevermind. Under the hood, xtdidreg uses time and unit FE. Your third command, unlike the first two, does not. So this likely explains the differences.

    Comment


    • #3
      Thank you for the reply.

      Here are some results regarding the matter.


      1. xtreg with time fixed effect.
      Code:
      Fixed-effects (within) regression               Number of obs     =    126,672
      Group variable: id                              Number of groups  =      1,218
      
      R-squared:                                      Obs per group:
      Within  = 0.3549                                         min =        104
      Between = 0.0183                                         avg =      104.0
      Overall = 0.0453                                         max =        104
      
      F(104,1217)       =     516.57
      corr(u_i, Xb) = -0.0205                         Prob > F          =     0.0000
      
      (Std. err. adjusted for 1,218 clusters in id)
      
      Robust
      ln_OFF  Coefficient  std. err.      t    P>t     [95% conf. interval]
      
      FC 
      Post     .8484489   .0098513    86.13   0.000     .8291215    .8677762
      
      over 
      Competitive            0  (omitted)
      
      FC#over 
      Post#Competitive    -.0738441    .008204    -9.00   0.000    -.0899396   -.0577486
      
      date 
      3069    -.0234435   .0036636    -6.40   0.000    -.0306311   -.0162559
      3070    -.0330616   .0038225    -8.65   0.000     -.040561   -.0255621
      3071    -.0464528   .0042592   -10.91   0.000     -.054809   -.0380966
      3072     .0142889   .0052425     2.73   0.007     .0040035    .0245743
      3073    -.0893196   .0055157   -16.19   0.000    -.1001409   -.0784984
      3074     .0305656   .0041074     7.44   0.000     .0225072    .0386239
      3075     .0101663   .0039318     2.59   0.010     .0024525      .01788
      3076     .0424484   .0036935    11.49   0.000      .035202    .0496948
      3077     .0078064   .0043448     1.80   0.073    -.0007176    .0163305
      3078     .0868084   .0050886    17.06   0.000     .0768251    .0967918
      3079     .0044045    .005164     0.85   0.394    -.0057269    .0145359
      3080     .0595264   .0050988    11.67   0.000      .049523    .0695298
      3081     .0201319   .0074393     2.71   0.007     .0055367    .0347271
      3082     .0174062   .0050331     3.46   0.001     .0075317    .0272808
      3083     .0111077    .004516     2.46   0.014     .0022476    .0199678
      3084    -.0032333   .0050638    -0.64   0.523    -.0131681    .0067014
      3085     .1035966   .0060528    17.12   0.000     .0917215    .1154717
      3086     .0976943   .0049776    19.63   0.000     .0879287      .10746
      3087     .0402426   .0047892     8.40   0.000     .0308466    .0496385
      3088    -.0088539   .0054759    -1.62   0.106    -.0195972    .0018894
      3089     .0467458   .0054523     8.57   0.000     .0360488    .0574428
      3090     .0053473   .0052373     1.02   0.307    -.0049278    .0156224
      3091     .0097629   .0056622     1.72   0.085    -.0013459    .0208718
      3092      .004486   .0054775     0.82   0.413    -.0062603    .0152324
      3093     .0261269   .0050716     5.15   0.000     .0161769    .0360769
      3094     .0162182   .0055287     2.93   0.003     .0053714     .027065
      3095     -.007476   .0055681    -1.34   0.180    -.0184002    .0034482
      3096     .0023746   .0053647     0.44   0.658    -.0081506    .0128997
      3097    -.0079741   .0052097    -1.53   0.126    -.0181951    .0022468
      3098     .0504102   .0071989     7.00   0.000     .0362864    .0645339
      3099     .0123666   .0058064     2.13   0.033     .0009751    .0237582
      3100      .012247   .0052193     2.35   0.019     .0020071    .0224869
      3101     .0208429   .0051306     4.06   0.000     .0107771    .0309086
      3102     .0437478   .0051812     8.44   0.000     .0335827     .053913
      3103    -.0472256   .0052696    -8.96   0.000    -.0575642   -.0368871
      3104     -.086758    .009557    -9.08   0.000     -.105508    -.068008
      3105    -.0171379   .0054514    -3.14   0.002    -.0278331   -.0064427
      3106     .0430576   .0054028     7.97   0.000     .0324578    .0536574
      3107    -.0051916   .0050485    -1.03   0.304    -.0150963    .0047132
      3108    -.0148988   .0052219    -2.85   0.004    -.0251438   -.0046539
      3109    -.0276678   .0054835    -5.05   0.000    -.0384261   -.0169096
      3110    -.0353024   .0057263    -6.16   0.000     -.046537   -.0240678
      3111     .0195842    .005266     3.72   0.000     .0092529    .0299156
      3112     .0098852   .0062524     1.58   0.114    -.0023815    .0221519
      3113    -.0122257   .0061547    -1.99   0.047    -.0243007   -.0001508
      3114    -.0706925   .0057345   -12.33   0.000    -.0819431   -.0594419
      3115    -.0453573   .0077529    -5.85   0.000    -.0605678   -.0301468
      3116    -.0654352   .0073142    -8.95   0.000    -.0797851   -.0510853
      3117    -.0237825   .0054427    -4.37   0.000    -.0344607   -.0131043
      3118     .1351882   .0055964    24.16   0.000     .1242086    .1461679
      3119     .6674334   .0081739    81.65   0.000     .6513968      .68347
      3120    -.0112277   .0044752    -2.51   0.012    -.0200076   -.0024478
      3121    -.0231867   .0053556    -4.33   0.000    -.0336939   -.0126795
      3122    -.0643617   .0050951   -12.63   0.000    -.0743579   -.0543655
      3123    -.1145721   .0093972   -12.19   0.000    -.1330086   -.0961357
      3124    -.0059702   .0051989    -1.15   0.251      -.01617    .0042296
      3125    -.0500152   .0054337    -9.20   0.000    -.0606755   -.0393548
      3126    -.0298146   .0049851    -5.98   0.000     -.039595   -.0200342
      3127    -.0646914   .0056753   -11.40   0.000    -.0758259   -.0535569
      3128    -.0428028   .0068511    -6.25   0.000     -.056244   -.0293616
      3129     -.876342   .0085777  -102.17   0.000    -.8931706   -.8595133
      3130    -.8266008   .0087786   -94.16   0.000    -.8438236   -.8093779
      3131    -.8838929   .0087349  -101.19   0.000      -.90103   -.8667557
      3132    -.8160397   .0076634  -106.48   0.000    -.8310748   -.8010047
      3133    -.8444588   .0099651   -84.74   0.000    -.8640095   -.8249082
      3134    -.8330202   .0084397   -98.70   0.000    -.8495781   -.8164623
      3135    -.8632482   .0087911   -98.20   0.000    -.8804955   -.8460009
      3136    -.8427622   .0093915   -89.74   0.000    -.8611876   -.8243369
      3137    -.6987716   .0094882   -73.65   0.000    -.7173866   -.6801567
      3138    -.7271565   .0085106   -85.44   0.000    -.7438536   -.7104595
      3139    -.7370376   .0089173   -82.65   0.000    -.7545327   -.7195426
      3140    -.7982379     .00916   -87.14   0.000     -.816209   -.7802667
      3141    -.7480058   .0097701   -76.56   0.000     -.767174   -.7288375
      3142    -.8562893   .0093299   -91.78   0.000    -.8745939   -.8379848
      3143    -.8771425    .009329   -94.02   0.000    -.8954452   -.8588398
      3144    -.8738573   .0090901   -96.13   0.000    -.8916912   -.8560233
      3145    -.8256514   .0085571   -96.49   0.000    -.8424398   -.8088631
      3146    -.8254862   .0091005   -90.71   0.000    -.8433406   -.8076318
      3147    -.8577879   .0087985   -97.49   0.000    -.8750498    -.840526
      3148    -.8553055   .0082971  -103.09   0.000    -.8715837   -.8390274
      3149    -.8940692   .0085779  -104.23   0.000    -.9108983     -.87724
      3150    -.8125704   .0103076   -78.83   0.000    -.8327931   -.7923478
      3151    -.8668659   .0087955   -98.56   0.000    -.8841218   -.8496099
      3152    -.8505619   .0084984  -100.08   0.000    -.8672351   -.8338888
      3153    -.8282254   .0086122   -96.17   0.000    -.8451219   -.8113289
      3154    -.7951754    .007175  -110.83   0.000    -.8092521   -.7810988
      3155    -.8727308   .0076656  -113.85   0.000    -.8877702   -.8576915
      3156    -.8962792   .0074175  -120.83   0.000    -.9108318   -.8817267
      3157    -.8933396   .0084234  -106.05   0.000    -.9098655   -.8768137
      3158    -.8297725   .0090092   -92.10   0.000    -.8474478   -.8120972
      3159    -.9730041   .0107696   -90.35   0.000    -.9941332    -.951875
      3160     -.901572   .0090566   -99.55   0.000    -.9193402   -.8838038
      3161    -.9210881   .0100153   -91.97   0.000    -.9407372   -.9014389
      3162    -.9537892   .0100102   -95.28   0.000    -.9734283     -.93415
      3163     -.816505   .0093232   -87.58   0.000    -.8347963   -.7982136
      3164    -.9155536   .0098286   -93.15   0.000    -.9348365   -.8962707
      3165    -.9154131   .0098828   -92.63   0.000    -.9348024   -.8960238
      3166    -.9363869   .0098447   -95.12   0.000    -.9557014   -.9170725
      3167    -.8486302   .0093263   -90.99   0.000    -.8669276   -.8303328
      3168    -.8616797   .0108798   -79.20   0.000    -.8830249   -.8403344
      3169    -.9175595   .0097108   -94.49   0.000    -.9366113   -.8985076
      3170    -.8577555   .0074374  -115.33   0.000    -.8723471    -.843164
      3171            0  (omitted)
      
      _cons    16.26473   .0039452  4122.71   0.000     16.25699    16.27247
      
      sigma_u   .47809263
      sigma_e   .16070603
      rho   .89848061   (fraction of variance due to u_i)


      2. xtdidreg
      Code:
      Number of groups and treatment time
      
      Time variable: date
      Control:       treat = 0
      Treatment:     treat = 1
      
      Control  Treatment
      
      Group        
      id        763        455
      
      Time         
      Minimum       3068       3129
      Maximum       3068       3129
      
      
      Difference-in-differences regression    Number of obs = 126,672
      Data type: Longitudinal
      
      (Std.    err. adjusted for 1,218 clusters in id)
          
      Robust
      ln_OFF  Coefficient  std. err.    t    P>t     [95% conf. interval]
          
      ATET         
      treat 
      (1 vs 0)    -.0738441    .008204    -9.00   0.000    -.0899396   -.0577486
          
      Note: ATET estimate adjusted for panel    effects and time effects.

      3. reghdfe
      Code:
      HDFE Linear regression                            Number of obs   =    126,672
      Absorbing 2 HDFE groups                           F(   1, 125350) =    1501.82
      Prob > F        =     0.0000
      R-squared       =     0.9039
      Adj R-squared   =     0.9029
      Within R-sq.    =     0.0120
      Root MSE        =     0.1607
      
      
      Robust
      ln_OFF  Coefficient  std. err.      t    P>t     [95% conf. interval]
      
      FC 
      Post            0  (omitted)
      
      over 
      Competitive            0  (omitted)
      
      FC#over 
      Post#Competitive    -.0738441   .0019055   -38.75   0.000    -.0775788   -.0701094
      
      _cons    16.27677   .0005308  3.1e+04   0.000     16.27573    16.27781
      
      
      Absorbed degrees of freedom:
      
      Absorbed FE  Categories  - Redundant  = Num. Coefs 
      -
      date        104           0         104     
      id       1218           1        1217
      @Jared, for the third command, reghdfe, I've specified to absorb time (date) and id level fixed effect, and the reghdfe command is the only command that returns the expected result (as per my understanding goes).

      Here, FC is binary time variant, and over is binary group identifier.

      So, to re-address my question, why does FC in the xtreg command not omitted like the one in reghdfe?

      Thank you.

      Comment


      • #4
        🤷🤷🤷🤷 I don't know honestly. Considering the point estimates are the same, this tells me something with the SEs are being calculated differently under the hood. I'm unsure what the issue is here.

        Comment


        • #5
          Thank you for the reply though!

          I'll have to well go open up the under the hood and see how exactly all three command works I guess...

          Comment


          • #6
            I wouldn't worry about this too much. Unless the implications are wildly different, then unless you just wanna know the underlying machinations (which I'm definitely guilty of in my own work!!!!), I wouldn't lose sleep over it. Stata already makes me lose sleep in other ways, I try not to add other reasons to the list.

            But, you could email the author of the command. Presumably he's better insight than a mere mortal like myself.

            Comment


            • #7
              I agree. I don't really think this is going to be a main game changer, but I'll definitely try sending an email to the authors of above commands when I have extra time Thanks a bunch.

              Comment

              Working...
              X