I'd like to understand how the -xthdidregress ra- command calculates the ATET. I'm using Stata/MP 18.0. I'm able to manually calculate the ATET correctly for each period after treatment, but my estimates are incorrect in the periods prior to treatment.
Setup
I have panel data on four states from time period t=15 to 40 (data copied below). One state, West Virginia (state_code=50), is treated beginning in period t=22. The other states are never treated. Using -xthdidregress-, I calculate the ATET in each period:
which gives the following estimates:

My understanding was that these coefficients represent the difference in yvar in each period between the treated state and the never treated states. Since there is no coefficient for t=15, I assume that we are normalizing it to 0. In order to make sure I understand correctly, I try to recreate these coefficients from scratch.
Attempt 1
which gives the following estimates:

The pattern seems about right, but the estimates are clearly different.
Attempt 2
If instead I recenter around the t=21, the period immediately before treatment, I get the coefficients for t>=22 exactly right. But, the earlier coefficients are still wrong.

Attempt 3
Finally, here is an equivalent version of attempt 2 that doesn't use -gcollapse-.
In summary, I can calculate the ATET correctly for the post-treatment periods, but I'm clearly missing something as far as the pre-treatment periods. I'd be surprised if there were actually two separate procedures to calculate the pre- and post-period ATETs, so I'm guessing that my intuition about what the command is doing is incorrect. I'd appreciate any advice.
Setup
I have panel data on four states from time period t=15 to 40 (data copied below). One state, West Virginia (state_code=50), is treated beginning in period t=22. The other states are never treated. Using -xthdidregress-, I calculate the ATET in each period:
Code:
xtset state_code t xthdidregress ra (yvar) (treatment_var), group(state_code) estat atetplot
My understanding was that these coefficients represent the difference in yvar in each period between the treated state and the never treated states. Since there is no coefficient for t=15, I assume that we are normalizing it to 0. In order to make sure I understand correctly, I try to recreate these coefficients from scratch.
Attempt 1
Code:
* Trying to manually calculate the ATET preserve gcollapse yvar, by(_did_cohort t) reshape wide yvar, i(t) j(_did_cohort) gen difference = yvar22 - yvar0 gen center = difference if t==15 replace center = center[1] gen atet = difference - center twoway connected atet t, xline(21) /// xlabel(10(10)40) yline(0) ylabel(-15(5)5) restore
The pattern seems about right, but the estimates are clearly different.
Attempt 2
If instead I recenter around the t=21, the period immediately before treatment, I get the coefficients for t>=22 exactly right. But, the earlier coefficients are still wrong.
Code:
preserve gcollapse yvar, by(_did_cohort t) reshape wide yvar, i(t) j(_did_cohort) gen difference = yvar22 - yvar0 gen center = difference if t==21 replace center = center[7] // bit of a hack to recenter gen atet = difference - center twoway connected atet t, xline(21) /// xlabel(10(10)40) yline(0) ylabel(-15(5)5) restore
Attempt 3
Finally, here is an equivalent version of attempt 2 that doesn't use -gcollapse-.
Code:
* Equivalent approach without collapsing reg yvar i.t if _did_cohort==0 predict mhat, xb gen atet = yvar - mhat if _did_cohort==22 gen center = atet if t==21 bysort _did_cohort: egen center_max = max(center) replace atet = atet - center_max twoway connected atet t if _did_cohort==22, xline(21) /// xlabel(10(10)40) yline(0) ylabel(-15(5)5)
Code:
* Example generated by -dataex-. For more info, type help dataex clear input float(yvar date t) long state_code float treatment_var 15.48513 202 15 6 0 15.72585 203 16 6 0 15.925879 204 17 6 0 16.269817 205 18 6 0 16.45096 206 19 6 0 15.775162 207 20 6 0 16.349216 208 21 6 0 16.380201 209 22 6 0 16.644821 210 23 6 0 16.963497 211 24 6 0 15.247427 212 25 6 0 14.532273 213 26 6 0 15.245345 214 27 6 0 15.190864 215 28 6 0 14.373366 216 29 6 0 14.372738 217 30 6 0 14.459294 218 31 6 0 14.425225 219 32 6 0 13.76663 220 33 6 0 13.70272 221 34 6 0 13.949927 222 35 6 0 14.058516 223 36 6 0 13.268163 224 37 6 0 12.94921 225 38 6 0 12.758443 226 39 6 0 12.18474 227 40 6 0 32.836536 202 15 8 0 33.09925 203 16 8 0 33.805603 204 17 8 0 35.038982 205 18 8 0 35.24295 206 19 8 0 35.345726 207 20 8 0 31.71864 208 21 8 0 31.059637 209 22 8 0 30.057047 210 23 8 0 30.07797 211 24 8 0 27.192354 212 25 8 0 28.09544 213 26 8 0 28.268705 214 27 8 0 27.712704 215 28 8 0 27.565866 216 29 8 0 27.00981 217 30 8 0 28.08877 218 31 8 0 27.2892 219 32 8 0 26.119316 220 33 8 0 26.578644 221 34 8 0 26.56049 222 35 8 0 27.08266 223 36 8 0 26.081926 224 37 8 0 25.714 225 38 8 0 25.593884 226 39 8 0 22.621666 227 40 8 0 13.697414 202 15 9 0 13.828605 203 16 9 0 13.30723 204 17 9 0 13.292938 205 18 9 0 12.665986 206 19 9 0 12.207777 207 20 9 0 12.806787 208 21 9 0 11.970038 209 22 9 0 12.354688 210 23 9 0 12.440425 211 24 9 0 11.497087 212 25 9 0 11.378276 213 26 9 0 12.242064 214 27 9 0 11.282948 215 28 9 0 10.674518 216 29 9 0 11.858283 217 30 9 0 10.82375 218 31 9 0 11.259423 219 32 9 0 10.58102 220 33 9 0 10.740476 221 34 9 0 10.472117 222 35 9 0 10.894774 223 36 9 0 10.301176 224 37 9 0 10.201314 225 38 9 0 10.150612 226 39 9 0 8.140618 227 40 9 0 26.615303 202 15 50 0 26.99366 203 16 50 0 27.320904 204 17 50 0 27.346266 205 18 50 0 27.98667 206 19 50 0 28.089935 207 20 50 0 28.10553 208 21 50 0 27.9229 209 22 50 1 27.838293 210 23 50 1 28.183153 211 24 50 1 26.817026 212 25 50 1 27.129515 213 26 50 1 27.15126 214 27 50 1 26.80359 215 28 50 1 26.056345 216 29 50 1 26.63486 217 30 50 1 27.07756 218 31 50 1 25.72048 219 32 50 1 24.775146 220 33 50 1 24.457024 221 34 50 1 23.38469 222 35 50 1 22.576775 223 36 50 1 end format %tq date label values state_code state_code label def state_code 6 "Colorado", modify label def state_code 8 "Delaware", modify label def state_code 9 "District of Columbia", modify label def state_code 50 "West Virginia", modify
Comment