做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