tempname resmat
forvalues i = 1/21 {
synth value density value(2004) value(2000) value(1996) , trunit(`i') trperiod(2005) xperiod(1996(1)2004)
matrix `resmat' = nullmat(`resmat') \ e(RMSPE)
local names `"`names' `"`i'"'"'
}
mat colnames `resmat' = "RMSPE"
mat rownames `resmat' = `names'
matlist `resmat' , row("Treated Unit")
use smoking, clear
** ask stata i am panel data
tsset y year
** loop through units
forval i=1/69{
qui synth value density value(2004) value(2000) value(1996), ///
xperiod(1996(1)2004) trunit(`i') trperiod(2005) keep(synth_`i', replace)
}
*
forval i=1/69{
use synth_`i', clear
rename _time years
gen tr_effect_`i' = _Y_treated - _Y_synthetic
keep years tr_effect_`i'
drop if missing(years)
save synth_`i', replace
}
****
use synth_1, clear
forval i=2/69{
qui merge 1:1 years using synth_`i', nogenerate
}
***
local lp
forval i=1/69 {
local lp `lp' line tr_effect_`i' years, lcolor(gs12) ||
}
*
* create plot
twoway `lp' || line tr_effect_1 years, ///
lcolor(orange) legend(off) xline(2005, lpattern(dash))