做US GDP相关的图
代码如下:
import excel us_gdp.xlsx, firstrow case(lower) clear
tsset year
label variable gdp_growth_rate "GDP GROWTH RATE"
twoway ///
function y=20,range(1929 1933) recast(area) color(green) base(0) yaxis(1) || ///
function y=20,range(1970 1983) recast(area) color(midblue) base(0) yaxis(1)|| ///
function y=20,range(2008 2009) recast(area) color(red) base(0) yaxis(1) || ///
function y=0.0333977,range(1929 2017) yaxis(2) lcolor(purple) || ///
tsline ngdp,lp(dash) yaxis(1) ytitle("GDP" "(unit: trillion)") || ///
tsline rgdp,lp(shortdash) yaxis(1) || ///
tsline gdp_growth_rate,yaxis(2) xlabel(1929(8)2017) ///
ytitle("GDP GROWTH RATE" "(based on RGDP)",axis(2)) xtitle("year") ///
legend(order(1 "Great Depression" 2 "Stagflation" 3 "Financial Crisis" ///
4 "NGDP" 5 "RGDP" 6 "GDP GROWTH RATE")) scheme(s1color) ///
note("Source:Bureau of Economic Analysis")
graph export us_gdp.pdf,replace
做出的图如下:
做US inflation相关的图
代码1
import excel us_infla_unr_gdpr.xlsx, firstrow case(lower) clear
rename inflation inflation_rate
label variable unr "Unemployment rate"
label variable gdp_rate "gdp growth rate"
label variable inflation_rate "Inflation rate"
tsset year
twoway ///
function y=0.2,range(1970 1983) recas

这篇博客展示了如何使用Stata制作US GDP和inflation相关图表,包括绘制带有区间阴影的图表和美观的柱状图。通过一系列代码示例,详细解释了每个图表的生成过程,并提供了进一步的参考资料链接。此外,作者还邀请读者关注其新浪微博,获取更多关于Stata、Latex和Matlab的技巧分享。

最低0.47元/天 解锁文章
7851

被折叠的 条评论
为什么被折叠?



