For an estimator, I'm interested in keeping a certain set of treated units which have a given number of before and after treatment periods. If a unit only as one month of post-intervention data, that's much less helpful than a unit with 6 or 12 months (generally speaking), so I want users to be able to restrict their sample, when possible, to however many pre and post observations they choose. The following code gives you my real data, provided by the fine people at Github.
Note that I use the labvars command from SSC, but this isn't integral here and can be commented out if you so choose.
Let's say for some silly reason, I'm only interested in keeping treated units with 20 years of pre intervention observations and 15 years post, dropping treated units that don't meet these restrictions. The code I've tried to do this is
but when we do this, we keep only Catalan, when what I want is to get rid of the Basque Country since its pre-intervention periods doesn't extend to -20.
How might I solve this?
Note that I use the labvars command from SSC, but this isn't integral here and can be commented out if you so choose.
Code:
* Basque Example loc int_time = 1975 qui { import delim "https://raw.githubusercontent.com/SucreRouge/synth_control/master/basque.csv", clear *sysuse basque, clear replace regionname = "Pais Vasco" if regionname == "Basque Country (Pais Vasco)" labvars year gdpcap "Year" "ln(GDP per 100,000)" egen id = group(regionname), label(regionname) // makes a unique ID *drop if year < 1960 xtset id year, y drop if id == 18 g treated = 1 if id == 15 & year > = 1970 replace treated = 1 if inlist(id,9) & year > = 1975 replace treated = 0 if mi(treated) g rel = . qui levelsof id if treated ==1, l(states) foreach x of loc states { qui su year if treated ==1 & id ==`x' replace rel = year- r(min) if id ==`x' } keep if inlist(id,9,15,8) }
Code:
loc before = -20 loc after = 15 qui levelsof id if !mi(rel), l(present) foreach l of loc present { su rel if id ==`l' cap as inrange(rel,`before',`after') if id ==`l' if _rc { drop if id ==`l' } } br
How might I solve this?
Comment