I have a question that relates to difference in difference estimation and plots of treatment effects over time. I have created some toy data to illustrate and would just like to verify that this is the correct approach.
To illustrate the effect of a treatment over time you would do something like:
Whereas the standard set up would look something like
Is that correct?
Here’s what I see in many journals. Just would like to verify that above is correct.

Lastly, how would I reconfigure the code above to create “years relative to the intervention” (which in this case is 2011)?
Here’s the toy data:
Thanks,
Justin
To illustrate the effect of a treatment over time you would do something like:
Code:
xtreg y i.treated##i.year x , fe margins year, dydx(treated) noestimcheck marginsplot
Code:
xtreg y x i.treated##i.post i.year , fe
Here’s what I see in many journals. Just would like to verify that above is correct.
Lastly, how would I reconfigure the code above to create “years relative to the intervention” (which in this case is 2011)?
Here’s the toy data:
Code:
clear
set more off
set seed 12345
set obs 10
gen int firm = _n
expand 15
bys firm: gen year = 2000 + _n
gen y = runiform(10,50)
gen x = runiform(1,20)
gen int treated = (firm >= 8)
gen int post = (year >= 2011)
replace y = 50 + x if year >= 2011 & treated == 1
xtset firm year
* standard did
xtreg y x i.treated##i.post i.year , fe
* effect over time
xtreg y i.treated##i.year x , fe
* plot effect over time
margins year, dydx(treated) noestimcheck
marginsplot , xline(2011) level(50) xlab(, angle(v)) xtitle("")
Justin

Comment