Dear all,

I am trying to generate graphs using loops and levelsof by regions and would like to save them before combining. I am using the code and data below.

The code for the graph runs but I get the following error for the saving part;

Code:
file m_`"Australia and New Zealand"'.gph could not be opened
I realize that this is due to the values of the region variable but I cannot figure it out. Any help will be greatly appreciated.

Thank you.

Regards,

Chiara

Code:
levelsof region, local(levelregion)
    foreach i of local levelregion {
    lowess m year if region== `"`i'"', mean recast(line) ///
    ylabel(#3, nogrid labsize(small)) graphregion(color(white)) bgcolor(white) ///
    title(`"`i'"') ytitle("M", size(small)) yscale(titlegap(3)) xtitle(Year) ///
    addplot(lowess y year if region== `"`i'"', yaxis(2) ///
    ytitle("Y", size(small) axis(2)) ylabel(#3, labsize(small) axis(2)) yscale(titlegap(3) axis(2))) ///
    legend(label(1 "M") label(2 "Smoothed mean") label(3 "Y") cols(3) size(small)) note(" ") ///
    saving(m_`"`i'"', replace)
    }
Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input double year str25 region double(m y)
2015 "Australia and New Zealand"     98705  .2765869229357915
2016 "Australia and New Zealand"   95986.5 .37403115455331665
2015 "Central America"           21463.375  .3542487725205664
2016 "Central America"             23297.5 .35364366336919867
end