I would like to create a PDF of multiple graphs.
Below is the code that I have and works. I'd basically like to run it for an entire variable list, for example by using a loop, and ideally combine it into a single PDF.
Code:
xtline income if inlist(stateabbr, "RI", "VT", "MD", "NV")), overlay title(income) plot1(lc(sienna)) plot2(lc(dknavy)) plot3(lc(forest_green)) plot4(lc(orange)) plot5(lc(sand)) plot6(lc(edkblue)) xtitle("year") legend(order(1 4 2 3)) graph export "/Results/Figures/graphs.pdf", replace
The code sample I have is as follows:
Code:
if "`varlist'" == "" local varlist "income gdp employment" tokenize `varlist' local varlist_vlist local i = 1 while "``i''" != "" { local varlist_vlist `varlist_vlist' ``i'' local i = `i' + 1 } foreach var of `varlist_vlist' { xtline `v' if inlist(stateabbr, "RI", "VT", "MD", "NV"), overlay title("`v'"") plot1(lc(sienna)) plot2(lc(dknavy)) plot3(lc(forest_green)) plot4(lc(orange)) plot5(lc(sand)) plot6(lc(edkblue)) xtitle("Year") legend(order(1 4 2 3)) graph export "/Results/Figures/graphs.pdf", replace }
I've also tried
Code:
foreach var in `varlist_vlist' { preserve local label: var label `var' xtline `var' if inlist(stateabbr, "RI", "VT", "MD", "NV"), overlay title(log_real_pinc_pc) plot1(lc(sienna)) plot2(lc(dknavy)) plot3(lc(forest_green)) plot4(lc(orange)) plot5(lc(sand)) plot6(lc(edkblue)) xtitle("year") legend(order(1 4 2 3)) graph export "Results/Figures/graphs2.pdf", replace restore }
I'd appreciate any advice and insights you have!
0 Response to Creating PDF of Multiple Graphs using Loops
Post a Comment