egen group = cut(年份), at(1951 1978 2001 2021) icodes
添加赋值标签:
label def groupval 0 "1951~1977" 1 "1978~2000" 2 "2001~2020" label val group groupval
ren 地区生产总值_亿元 gdp ren 年份 year
将单位转换成万亿元:
replace gdp = gdp / 10000
之后根据时间组的分段构建三个不同的模型,先设置回归表的系数格式:
set cformat %6.2f
构造回归方程:
*- 模型 1 reg gdp year if group == 0 local eq1 "y = `=string(`=_b[_cons]', "%6.2f")' + `=string(`=_b[year]', "%6.2f")'x, R{superscript:2} = `=string(`e(r2)', "%6.2f")', P < 0.01" *- 模型 2 reg gdp year if group == 1 local eq2 "y = `=string(`=_b[_cons]', "%6.2f")' + `=string(`=_b[year]', "%6.2f")'x, R{superscript:2} = `=string(`e(r2)', "%6.2f")', P < 0.01" *- 模型 3 reg gdp year if group == 2 local eq3 "y = `=string(`=_b[_cons]', "%6.2f")' + `=string(`=_b[year]', "%6.2f")'x, R{superscript:2} = `=string(`e(r2)', "%6.2f")', P < 0.01"
然后就可以使用 Stata 绘图了:
tw sc gdp year if group == 0, m(s) mc("0 115 194") msize(*0.5) || /// lfit gdp year if group == 0, lc("0 115 194") lp(solid) || /// sc gdp year if group == 1, m(s) mc("239 192 0") msize(*0.5) || /// lfit gdp year if group == 1, lc("239 192 0") lp(solid) || /// sc gdp year if group == 2, m(s) mc("205 83 76") msize(*0.5) || /// lfit gdp year if group == 2, lc("205 83 76") lp(solid) || /// lpolyci gdp year, color("134 134 134") /// leg(order(1 "1951~1977年,线性显著" 3 "1978~2000年,线性显著" 5 "2001~2020年,线性显著") /// pos(11) ring(0)) /// xti("年份") yti("GDP(万亿元)") /// sch(qleanmono) /// xla(1950(5)2022) || /// scatteri 8 1965 `"`eq1'"', m(i) mlabc("0 115 194") mlabpos(0) mlabang(0) || /// scatteri 11 1990 `"`eq2'"', m(i) mlabc("239 192 0") mlabpos(0) mlabang(9) || /// scatteri 60 2010 `"`eq3'"', m(i) mlabc("205 83 76") mlabpos(0) mlabang(62) /// xsize(10) ysize(6)
gr export "pic1.png", width(4800)
导出插入 word 中的矢量图
另外大家经常会使用 word 撰写论文,如何在 word 中插入矢量图呢?
word 中支持的矢量图格式主要是 emf,在 Stata 中可以直接使用 graph export 命令导出:
评论