|
多时点DID平行趋势检验代码
global X "控制变量"
*平行趋势检验-事件研究法
gen policy = year - branch_reform //生成政策时点前后期数,branch_reform是政策实施年份
tab policy
replace policy = -10 if policy < -10
replace policy = 15 if policy > 15
forvalues i=10(-1)1{
gen pre`i'=(policy==-`i')
}
gen current= (policy==0)
forvalues i=1(1)15{
gen post`i'=(policy==`i')
}
drop pre1 //将政策前第一期作为基准组,很重要!!!
*两个命令结果一样
xtreg y pre* current post* i.year, fe vce(cluster ID)
reghdfe y pre* current post*, absorb(ID year) vce(cluster ID)
*绘图
coefplot, baselevels ///
keep(pre* current post*) ///
vertical ///转置图形
coeflabels( pre10 = "-10" ///
pre9 = "-9" ///
pre8 = "-8" ///
pre7 = "-7" ///
pre6 = "-6" ///
pre5 = "-5" ///
pre4 = "-4" ///
pre3 = "-3" ///
pre2 = "-2" ///
current = "0" ///
post1 = "1" ///
post2 = "2" ///
post3 = "3" ///
post4 = "4" ///
post5 = "5" ///
post6 = "6" ///
post7 = "7" ///
post8 = "8" ///
post9 = "9" ///
post10 = "10" ///
post11 = "11" ///
post12 = "12" ///
post13 = "13" ///
post14 = "14" ///
post15 = "15") ///
yline(0,lcolor(edkblue*0.8)) ///加入y=0这条虚线
ylabel(-0.06(0.02)0.06) ///
xline(10, lwidth(vthin) lpattern(dash) lcolor(teal)) ///
ylabel(,labsize(*0.75)) xlabel(,labsize(*0.75)) ///
ytitle("政策动态经济效应", size(small)) ///加入Y轴标题,大小small
xtitle("政策时点", size(small)) ///加入X轴标题,大小small
addplot(line @b @at) ///增加点之间的连线
ciopts(lpattern(dash) recast(rcap) msize(medium)) ///CI为虚线上下封口
msymbol(circle_hollow) ///plot空心格式
scheme(s1mono)
|