Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Problem with using loop and graph combine


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: Problem with using loop and graph combine
Date   Wed, 3 Oct 2012 08:27:13 +0100

The main issue is what you are typing as your -graph combine- command
outside the loop (not in). You don't show that to us.

Consider the following

sysuse auto
scatter mpg weight
graph save foo

. graph combine foo
foo is not a memory graph
r(198);

. graph combine "foo"

<worked>

My guess is that you are omitting the " ". That is a little tricky to
reverse. Here is one way of doing it:

sysuse auto, clear
forval i = 1/5 {
	histogram mpg if rep78 == `i', saving(foo`i', replace)
	local foo `foo' "foo`i'"
}
local foo : subinstr local foo "foo1" `""foo1""'
graph combine `foo'

Nick

On Wed, Oct 3, 2012 at 3:07 AM, saeid shahraz <[email protected]> wrote:

> I am seeking for help as for using graph combine command in a loop.
> Here is the intro to the problem.
>
> I have number of death for 168 countries for 3 years.
> Variables: country (string 3 digit ISO codes), year(numeric) death(numeric)
>
> I tested my scripts on the first 5 countries and got rid of the rest of data.
>
> Here is the script:
>
> levelsof country, local(b)
>                            foreach i of local b{
>                            graph drop _all
>                            graph hbar Deaths_B_total,
> over(year,lab(labsize(small)) gap(200)) title("`i'") name(`i')
>                    *gr save  ("`i'")
>                     local z "`z' `i'"
>                     }
>
> Result: It creates the individual graphs one at a time but produces
> the following error message in the end:
>
> AFG is not a memory graph
> r(198)
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index