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
Any precise way to convert dialy to monthly: string 1/1/2019 to numeric 20190101?I have daily data in string format as 1/1/ 2019. The string length is different as there as values e…
How to assign the same value to all members of a group if a condition on a certain variable occures AT LEAST once in the same groupHi Statalist experts, I would need a little help. I'm working with a dataset containing the followi…
Creating Composite Variable (from non-mutually exclusive categorial variables)Hi All, I am quite new to Stata. I have five variables which each ask whether cannabis has been con…
summary statistics with standard error in parenthesesI want to make a table of summary statistics with standard error in parentheses, as well as the obse…
Margins not estimableHello! I am trying to look at the effect mandatory elections (Valplikt) has on satisfaction with dem…
Subscribe to:
Post Comments (Atom)
0 Response to Creating and Saving graphs using loop
Post a Comment