问题描述
我想使用下面的代码在 Stata 中绘制系数图。
然而,有一个问题。
twoway (scatter dv2 coef if controls=="basic",mcolor(blue) msize() lp(solid) msymbol(o) lwi(vthin) lcolor(blue)) ///
(rcap ci_upper ci_lower dv2 if controls=="basic",hor msymbol(dot) lwi() mcolor(blue) lcolor(blue) lp(dash)) ///
(scatter dv2 coef if controls=="w/o sampling weight",mcolor(red) msize() lp(dash) msymbol(s) lwi(vthin) lcolor(red)) ///
(rcap ci_upper ci_lower dv2 if controls=="w/o sampling weight",hor msymbol(dot) lwi() mcolor(red) lcolor(red) lp(dash)),///
title(Industry) ytick(,grid) /*ylabel(1 "`: label (age_cat) 1'" 2 "`: label (age_cat) 2'" 3 "`: label (age_cat) 3'" 4 "`: label (age_cat) 4'",///
labsize(small))*/ legend(pos(6) col(3) order(1 "with sampling weight" 3 "without sampling weight")) ///
ylabel() xtitle("Coefficient on Covid19 Pandemic",size(small)) xline(0,lc(black) lp(dash)) xlabel(-0.2(0.05)0.2) plotregion(margin(.1)) graphregion(color(white)) bgcolor(white) xtit() ytit("",size(small))
但是,我看到的图表重叠。我想移动我画的图形,但我不知道我需要什么代码。
解决方法
您需要抵消每个子集。这里 0.1 只是标记:使用任何适合您的值。如需更多讨论,请参阅 this paper。
gen dvb = dv2 + 0.1
gen dvc = dv2 - 0.1
twoway (scatter dvb coef if controls=="basic",mcolor(blue) msize() lp(solid) msymbol(o) lwi(vthin) lcolor(blue)) ///
(rcap ci_upper ci_lower dvb if controls=="basic",hor msymbol(dot) lwi() mcolor(blue) lcolor(blue) lp(dash)) ///
(scatter dvc coef if controls=="w/o sampling weight",mcolor(red) msize() lp(dash) msymbol(s) lwi(vthin) lcolor(red)) ///
(rcap ci_upper ci_lower dvc if controls=="w/o sampling weight",hor msymbol(dot) lwi() mcolor(red) lcolor(red) lp(dash)),///
title(Industry) ytick(,grid) /*ylabel(1 "`: label (age_cat) 1'" 2 "`: label (age_cat) 2'" 3 "`: label (age_cat) 3'" 4 "`: label (age_cat) 4'",///
labsize(small))*/ legend(pos(6) col(3) order(1 "with sampling weight" 3 "without sampling weight")) ///
ylabel() xtitle("Coefficient on Covid19 Pandemic",size(small)) xline(0,lc(black) lp(dash)) xlabel(-0.2(0.05)0.2) plotregion(margin(.1)) graphregion(color(white)) bgcolor(white) xtit() ytit("",size(small))