Dear Statalist Members,
I am working on a panel data set. I want to create graphs and save graphs by the country name.
If I use the following loop, it is creating graphs for all countries in my panel dataset. But it saves graphs by id such as 1.gph, 2.gph..... and so on.
levels country, local(countries)
local i = 1
foreach c of local countries {
twoway (line x y year if country=="`c'", title("`c'") ytitle(% of GDP) xtitle(Year))
graph save `i'.gph, replace
local i = `i' + 1
}
*
However, I WOULD LIKE TO SAVE GRAPHS BY COUNTRY NAME.
levels country, local(countries)
local i = 1
foreach c of local countries {
twoway (line x y year if country=="`c'", title("`c'") ytitle(% of GDP) xtitle(Year))
graph save `i'.gph, replace
local i = `i' + 1
}
*
This loop generates graphs and saves graphs IF THE COUNTRY NAME IS A SINGLE WORD. If the country name is India, the loop is fine. The loop stops working if the country name is MORE THAN 1 WORD such as United Kingdom or United States of America.
Any help will be greatly appreciated.
Thank you in advance.
Related Posts with Creating and Saving graphs using loop
Working Directory Keeps Changing by ItselfI am brand new to Stata, though I regularly use R. I am on a Mac. I am trying to set my working dir…
no observations r(2000) error after some observations, event study princetonHi everyone, I am running event study using princeton example https://dss.princeton.edu/online_hel.…
weakivtest for 2 endogenous variables caseHi Folks, I am using the -ivreg2- command with 2 endogenous variables, but don't know which weak in…
Ordered probit before applying ivregress 2sls commendBy following Dr. Woodridge's advice on Statalist, I applied the ordered probit before I ran the two-…
Removing numbers from text in labelsHi, I used sencode command in order to display the label's codes and text in the variable labels (in…
Subscribe to:
Post Comments (Atom)
0 Response to Creating and Saving graphs using loop
Post a Comment