Announcement

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

  • Standard errors with new -xthdidregress- command in Stata 18

    I am trying to understand how -xthdidregress- estimates standard errors for difference-in-differences with two-way fixed effects (TWFE). The help manual suggests standard errors are clustered by treatment level by default. However, using the -regress- command gives me different results. Does anyone know why?

    Reproducible example below using a panel of three states from 2001 to 2005. State 1's treatment begins in 2003. The point estimates of interest using -xthdidregress- and -regress- are identical, but their standard errors differ.

    Code:
    clear all
    
    input state year gdp post2003 treatmentGroup treated
    1 2001 100 0 1 0
    1 2002 115 0 1 0
    1 2003 95 1 1 1
    1 2004 87 1 1 1
    1 2005 73 1 1 1
    2 2001 113 0 0 0
    2 2002 117 0 0 0
    2 2003 121 1 0 0
    2 2004 125 1 0 0
    2 2005 129 1 0 0
    3 2001 47 0 0 0
    3 2002 53 0 0 0
    3 2003 59 1 0 0
    3 2004 62 1 0 0
    3 2005 66 1 0 0
    end
    
    *Set panel
    xtset state year, yearly
    Code:
    *xthdidregress using default VCE
    
    xthdidregress twfe (gdp) (treated), group(state) hettype(time)
    
    note: variable _did_cohort, containing cohort indicators formed by treatment variable treated and group variable state, was added to the dataset.
    
    Computing ATETs using margins ...
    
    Treatment and time information
    
    Time variable: year
    Time interval: 2001 to 2005
    Control:       _did_cohort = 0
    Treatment:     _did_cohort > 0
    -------------------------------
                      | _did_cohort
    ------------------+------------
    Number of cohorts |           2
    ------------------+------------
    Number of obs     |
        Never treated |          10
                 2003 |           5
    -------------------------------
    
    Heterogeneous-treatment-effects regression               Number of obs    = 15
                                                             Number of panels =  3
    Estimator:       Two-way fixed effects
    Panel variable:  state
    Treatment level: state
    Control group:   Never treated
    Heterogeneity:   Time
    
                                      (Std. err. adjusted for 3 clusters in state)
    ------------------------------------------------------------------------------
                 |               Robust
            Time |       ATET   std. err.      t    P>|t|     [95% conf. interval]
    -------------+----------------------------------------------------------------
            year |
           2003  |        -20   1.984313   -10.08   0.010    -28.53781   -11.46219
           2004  |      -31.5   1.322876   -23.81   0.002    -37.19187   -25.80813
           2005  |      -49.5   1.322876   -37.42   0.001    -55.19187   -43.80813
    ------------------------------------------------------------------------------
    Code:
    *xthdidregress explicitly specifying default VCE
    
    xthdidregress twfe (gdp) (treated), group(state) hettype(time) vce(cluster state)
    
    note: variable _did_cohort, containing cohort indicators formed by treatment variable treated and group variable state, was added to the dataset.
    
    Computing ATETs using margins ...
    
    Treatment and time information
    
    Time variable: year
    Time interval: 2001 to 2005
    Control:       _did_cohort = 0
    Treatment:     _did_cohort > 0
    -------------------------------
                      | _did_cohort
    ------------------+------------
    Number of cohorts |           2
    ------------------+------------
    Number of obs     |
        Never treated |          10
                 2003 |           5
    -------------------------------
    
    Heterogeneous-treatment-effects regression               Number of obs    = 15
                                                             Number of panels =  3
    Estimator:       Two-way fixed effects
    Panel variable:  state
    Treatment level: state
    Control group:   Never treated
    Heterogeneity:   Time
    
                                      (Std. err. adjusted for 3 clusters in state)
    ------------------------------------------------------------------------------
                 |               Robust
            Time |       ATET   std. err.      t    P>|t|     [95% conf. interval]
    -------------+----------------------------------------------------------------
            year |
           2003  |        -20   1.984313   -10.08   0.010    -28.53781   -11.46219
           2004  |      -31.5   1.322876   -23.81   0.002    -37.19187   -25.80813
           2005  |      -49.5   1.322876   -37.42   0.001    -55.19187   -43.80813
    ------------------------------------------------------------------------------
    Code:
    *regress
    
    reg gdp treated#i(2003/2005).year post2003 treatmentGroup i.state i.year, vce(cluster state)
    
    note: 3.state omitted because of collinearity.
    note: 2005.year omitted because of collinearity.
    
    Linear regression                               Number of obs     =         15
                                                    F(2, 2)           =          .
                                                    Prob > F          =          .
                                                    R-squared         =     0.9967
                                                    Root MSE          =     2.7544
    
                                        (Std. err. adjusted for 3 clusters in state)
    --------------------------------------------------------------------------------
                   |               Robust
               gdp | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
    ---------------+----------------------------------------------------------------
      treated#year |
           1 2003  |        -20   2.173707    -9.20   0.012     -29.3527    -10.6473
           1 2004  |      -31.5   1.449138   -21.74   0.002    -37.73514   -25.26486
           1 2005  |      -49.5   1.449138   -34.16   0.001    -55.73514   -43.26486
                   |
          post2003 |   19.16667   3.392803     5.65   0.030     4.568614    33.76472
    treatmentGroup |       56.8   1.014396    55.99   0.000      52.4354     61.1646
                   |
             state |
                2  |       63.6   2.70e-14  2.4e+15   0.000         63.6        63.6
                3  |          0  (omitted)
                   |
              year |
             2002  |   8.333333   5.660781     1.47   0.279    -16.02304    32.68971
             2003  |       -7.5   .7245688   -10.35   0.009    -10.61757   -4.382432
             2004  |         -4   2.36e-08 -1.7e+08   0.000           -4          -4
             2005  |          0  (omitted)
                   |
             _cons |   46.53333   3.165456    14.70   0.005     32.91348    60.15319
    --------------------------------------------------------------------------------

  • #2
    Dear Noah,

    You should get the same results if you exclude i.state from the list of regressors. We use the variable -state- and the treatment variable to form the cohort variable -_did_cohort-. It is the cohort variable that does the work of the treatment group.

    Best,

    Enrique
    Last edited by Enrique Pinzon (StataCorp); 29 Apr 2023, 20:09.

    Comment

    Working...
    X