I run this code. My data goes from 2022m1 to 2023m12. But when I make the graph, the period is extended all the way up to 1960m1. I don't know how to work around this. Any suggestions would be helpful.
gen treat_dist = month-tm(2022m12)
gen shifter = treat_dist + 12
summ shifter if treat_dist == -1
local true_neg = r(mean)
disp `true_neg'
drop if month < tm(2022m1)
summ shifter if treat_dist == -1
local true_neg = r(mean)
disp `true_neg'
reghdfe dv post ib`true_neg'.shifter##c.treatment_cont if Developing==1 & cat==1, abs(group month) cluster(group)
gen coef = .
gen se = .
levelsof shifter, l(times)
foreach t in `times' {
replace coef = _b[`t'.shifter#avg_`sco'] if shifter == `t'
replace se = _se[`t'.shifter#avg_`sco'] if shifter == `t'
}
disp `times'
* Make confidence intervals
cap g ci_top = coef+1.96*se
cap g ci_bottom = coef - 1.96*se
keep month coef se ci_*
duplicates drop
sort month
summ ci_top
local top_range = r(max)
summ ci_bottom
local bottom_range = r(min)
twoway (sc coef month) ///
(rcap ci_top ci_bottom month) ///
(function y = 0, range(month)) ///
(function y = -1, range(`bottom_range' `top_range') horiz) , ///
legend(off)
gen treat_dist = month-tm(2022m12)
gen shifter = treat_dist + 12
summ shifter if treat_dist == -1
local true_neg = r(mean)
disp `true_neg'
drop if month < tm(2022m1)
summ shifter if treat_dist == -1
local true_neg = r(mean)
disp `true_neg'
reghdfe dv post ib`true_neg'.shifter##c.treatment_cont if Developing==1 & cat==1, abs(group month) cluster(group)
gen coef = .
gen se = .
levelsof shifter, l(times)
foreach t in `times' {
replace coef = _b[`t'.shifter#avg_`sco'] if shifter == `t'
replace se = _se[`t'.shifter#avg_`sco'] if shifter == `t'
}
disp `times'
* Make confidence intervals
cap g ci_top = coef+1.96*se
cap g ci_bottom = coef - 1.96*se
keep month coef se ci_*
duplicates drop
sort month
summ ci_top
local top_range = r(max)
summ ci_bottom
local bottom_range = r(min)
twoway (sc coef month) ///
(rcap ci_top ci_bottom month) ///
(function y = 0, range(month)) ///
(function y = -1, range(`bottom_range' `top_range') horiz) , ///
legend(off)
Code:
* Example generated by -dataex-. For more info, type help dataex clear input float(month coef se ci_top ci_bottom) 744 -.04560159 .04456954 .0417547 -.13295789 745 .035214104 .04619185 .12575014 -.05532193 746 -.05389897 .04303712 .030453784 -.13825172 747 -.014382817 .04082957 .06564314 -.09440877 748 -.02137619 .04835052 .073390834 -.11614322 749 -.06010559 .04499692 .02808838 -.14829956 750 -.05081084 .0416654 .030853353 -.13247503 751 .006636559 .040455 .08592836 -.07265524 752 -.04418491 .04020809 .034622956 -.12299277 753 -.05142649 .04109575 .02912118 -.13197416 754 0 0 0 0 755 -.02560237 .04114302 .05503794 -.10624268 756 -.0001877204 .04576408 .08950988 -.08988532 757 -.01596871 .04283699 .0679918 -.09992922 758 -.04425317 .04183565 .03774472 -.12625106 759 -.0325988 .04125999 .04827078 -.11346838 760 -.08916704 .04567079 .0003477098 -.17868178 761 -.13920917 .04288281 -.05515886 -.2232595 762 -.06880311 .04861903 .026490185 -.1640964 763 -.13813807 .04564967 -.04866473 -.22761142 764 -.20903113 .04899104 -.1130087 -.3050536 765 -.1458779 .05587654 -.036359884 -.25539592 766 -.17964283 .04843017 -.08471969 -.27456596 767 -.08972433 .04444844 -.002605384 -.1768433 end format %tm month
Comment