Event Study from DID regression using coefplot

81 Views Asked by At

I am trying to create a event study plot that give me yearly average treatment effects on the treated on a business law on the average number of property firms relative to a control state where the business law is not in effect. Where am I going wrong with my code?

xtset county_id year

gen post = year >= sbdcopen
gen treated_post = treated * post

* Run the fixed-effects regression
xtreg prop_firms treated_post##c.year, fe

* Store the estimated coefficients
estimates store event_study

* Generate variable for the difference from mean
matrix mean_b = e(b)
gen diff_from_mean = prop_firms - mean_b[1, 1]

* Create coefplot for the event study
coefplot (diff_from_mean, label("Excess Prop Firms")) ///
    xline(0) ylabel("Difference from Mean") ///
    xlabel("Year relative to treatment") ///
    title("Event Study: Excess Prop Firms Over Time")

estimation result diff_from_mean not found
1

There are 1 best solutions below

1
krasnapolsky On

You have more control on the event study plot if you generate dummies for treated units for each year yourself. See example below:

forvalues i = 2004(2)2020 {
    gen dum_`i' = (year == `i')
    gen did_`i' = dum_`i' * treated
    drop dum_`i'
}
gen constant = 1
eststo event_interest: reghdfe outcomevar did_2004-did_2006 constant did_2010-did_2020, absorb(i.year i.county) vce(cluster county)

coefplot event_interest, omitted vertical yline(0, lcolor(black)) xline(4, lpattern(dash) lcolor(gray*0.5)) keep(did_* constant)

In this example, the treatment happens in 2010 (shown as xline(4)) and I replace the first pre-treatment period (2008) by a constant in order to avoid losing this in the coefplot.

Edit: variable names