Dear all,

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 variables I'd like to run this code for are: income, gdp, and employment. I'd like the title of each graph to have the title of the variable name.

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
}
Right now, I'm getting the error of "varlist required" so I think I did something wrong in setting it up. I can't tell if naming each graph according to the variable name (e.g. the income graph titled "income" would work either.

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 
}
Which doesn't lead to any error codes, but doesn't export anything either.

I'd appreciate any advice and insights you have!