stata - Combining multiple graphs with a loop -
stata - Combining multiple graphs with a loop -
i create multiple graphs , combine them using loop. used next code:
local var connecticut delaware minnesota missouri rhode island tennessee vermont wisconsin hawaii local n: word count `var' forvalues i=1/`n'{ local a: word `i' of `var' line prop_report_agencies modate if statename=="`a'" , ytitle(proportion_agency reports `a') saving(gg`a',replace) local gg `gg' "gg`a'" } local gg: subinstr local gg "gg`a'" `""gg`a'""' gr combine `gg' graph drop _all
when error
ggconnecticut not memory graph
the first part of code seems work: code creates graphs individually , stores them; however, cannot combine
due error.
first of all, let's right code, while shrinking meandering stream straight line:
local s connecticut delaware minnesota missouri "rhode island" tennessee vermont wisconsin hawaii foreach s of local s { line prop_report_agencies modate if statename=="`s'", ytitle(proportion_agency reports `s') saving(gg`s',replace) local gg `"`gg' "gg`s'""' } gr combine `gg'
in passing, note had bug rhode island
1 state, 2 words.
your major problem, however, guess, there conflict between role of " "
string delimiters , fact need them literal characters in combine
call. stop " "
beingness stripped need utilize compound double quotes. code shows know them. compound double quotes
`" "'
this illustration dopey nevertheless reproducible stata users using recent version of stata.
sysuse census, clear local s alabama "rhode island" foreach s of local s { histogram medage if state == "`s'", saving("gg`s'", replace) local gg `"`gg' "gg`s'""' } graph combine `gg'
in future, utilize
macro list
in debugging see problem is. guess " "
missing around connecticut
nowadays other states.
to see heart of problem, consider results of
local foo "bar" mac li
the local macro foo
not include quotation marks, have been stripped. insist on them, protect them compound double quotes.
local foo `""bar"' mac li
stata
Comments
Post a Comment