[关闭]
@liuyuxi 2021-07-19T09:23:26.000000Z 字数 3536 阅读 33

stata绘图

stata


合成控制绘图

  1. *合成控制基本结果图
  2. use synth_data,clear
  3. format _time %tm
  4. gen effect = _Y_treated- _Y_synthetic
  5. twoway (line _Y_treated _time, lcolor(black)) ///
  6. (line _Y_synthetic _time, lcolor(black)) ///
  7. (pcarrowi 103 686.5 103 689.5, lp(dash) lc(black*0.5) mcolor(black*0.5)) ///
  8. ,xline(690,lp(dash) lcolor(black*0.8) ) ///
  9. legend(size(*1)) ///
  10. ytitle("AQI") xtitle(" ") ///
  11. legend(col(1) pos(2 ) ) ///
  12. xlabel(684(3)703) ylabel(30(20)180) ///
  13. text(110 688 "Policy Month" ) ///
  14. legend(label(1 "Treated Group") label(2 "Untreated Group") label(3 " Policy Month")) ///
  15. legend(col(3) pos(6 ) )
  16. *合成控制净效应
  17. use synth_data,clear
  18. format _time %tm
  19. gen effect = _Y_treated- _Y_synthetic
  20. twoway (line effect _time, lcolor(black)) ///
  21. (pcarrowi -28 686.5 -28 689.5, lp(dash) lc(black*0.5) mcolor(black*0.5)) ///
  22. ,xline(690,lp(dash) lcolor(black*0.5) ) ///
  23. yline(0,lp(dash) lcolor(black*0.5) ) ///
  24. legend(size(*1)) ///
  25. ytitle("AQI") xtitle(" ") ///
  26. legend(col(1) pos(2 ) ) ///
  27. xlabel(684(3)703) ylabel(-50(10)10) ///
  28. text(-25 688 "Policy Month" ) ///
  29. legend(label(1 "Treated Effect") label(2 "Policy Month") ) ///
  30. legend(col(3) pos(6 ))

使用qlean,qleanmono等模板

模板

  1. . sysuse "auto.dta", clear . twoway scatter price weight
  2. . twoway scatter price weight, scheme(qlean)
  3. . twoway scatter price weight, scheme(qleanmono)
  4. . twoway scatter price weight if foreign==0 || scatter price weight if foreign==1
  5. . twoway scatter price weight if foreign==0 || scatter price weight if foreign==1, scheme(qlean)
  6. . twoway scatter price weight if foreign==0 || scatter price weight if foreign==1, scheme(qleanmono)
  7. . sysuse uslifeexp,clear. twoway line le_male year || line le_female year. twoway line le_male year || line le_female year, scheme(qlean)
  8. . twoway line le_male year || line le_female year, scheme(qleanmono)
  9. . sysuse lifeexp, clear. gen lgnppc = ln(gnppc)
  10. . gr matrix popgr lexp lgnp safe
  11. . gr matrix popgr lexp lgnp safe, scheme(qlean)
  12. . gr matrix popgr lexp lgnp safe, scheme(qleanmono)
  13. . sysuse nlsw88, clear. graph hbar (mean) wage, over(smsa) over(married) over(collgrad)
  14. . graph hbar (mean) wage, over(smsa) over(married) over(collgrad) scheme(qlean)
  15. . ssc install scheme_tufte, replace . ssc install scheme-burd, replace . net install gr0002_3.pkg
  16. . sysuse auto, clear. twoway lfitci mpg weight || scatter mpg weight. twoway lfitci mpg weight || scatter mpg weight, scheme(qlean) mc(ply3)
  17. . twoway lfitci mpg weight || scatter mpg weight, scheme(tufte)
  18. . twoway lfitci mpg weight || scatter mpg weight, scheme(burd)
  19. . twoway lfitci mpg weight || scatter mpg weight, scheme(lean1)
  20. . twoway lfitci mpg weight || scatter mpg weight, scheme(lean2)

使用plotplainplottig模板

  1. *散点图
  2. graph twoway (scatter nkill nevents if region==12 & nevents<=500 & nkill<=1000) ///
  3. (scatter nkill nevents if region==7 & nevents<=500 & nkill<=1000) ///
  4. (scatter nkill nevents if region==6 & nevents<=500 & nkill<=1000) ///
  5. , scheme(plottig) legend(label(1 Western Europe) label(2 North America) label(3 MENA)) name(s2m1) title("plottig")
  6. graph twoway (scatter nkill nevents if region==12 & nevents<=500 & nkill<=1000) ///
  7. (scatter nkill nevents if region==7 & nevents<=500 & nkill<=1000) ///
  8. (scatter nkill nevents if region==6 & nevents<=500 & nkill<=1000) ///
  9. , scheme(plottigblind) legend(label(1 Western Europe) label(2 North America) label(3 MENA)) name(s2c1) title("plottigblind")
  10. *折线图
  11. graph twoway (line nevents iyear if region==12) (line nevents iyear if region==7) (line nevents iyear if region==6), ///
  12. scheme(plottig) legend(order(1 "Western Europe" 2 "North America" 3 "MENA")) name(s2m2, replace) title("plottig") xline(2003) ///
  13. text(8 2003 "Iraq war", place(e))
  14. graph twoway (line nevents iyear if region==12) (line nevents iyear if region==7) (line nevents iyear if region==6), ///
  15. scheme(plottigblind) legend(order(1 "Western Europe" 2 "North America" 3 "MENA")) name(s2c2) title("plottigblind") xline(2003) ///
  16. text(8 2003 "Iraq war", place(e))
  17. *图形组合
  18. graph combine s2m1 s2c1 s2m2 s2c2, iscale(0.5)
  19. graph export plotplain5.eps, replace
  20. graph drop s2m1 s2c1 s2m2 s2c2
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注