Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


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

Re: st: Looping through graphs w/ foreach?


From   Nick Cox <njcoxstata@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Looping through graphs w/ foreach?
Date   Thu, 18 Aug 2011 16:33:23 +0100

For a slideshow, put -more- as the last line within the loop.

local empcategories "EMPJ EMPK EMPL EMPM EMPNEMPO EMPP EMPQ EMPR"
foreach var of local empcategories {
local graphtitle : variable label `var'
twoway line `var' `var'_neg Year if Mnemonic==trim("AMSTER")
more
}

In addition, note that your local -graphtitle- does nothing useful
unless you put the text somewhere on the graph.

Nick

On Thu, Aug 18, 2011 at 4:28 PM, Suran, Luciana @ CBRE EA
<Luciana.Suran@cbre.com> wrote:

> I am relearning Stata after a few years away using other statistical
> software so apologies for the introductory nature of this question.
>
> I have a time series dataset for ~ 20 cities - showing employment levels
> a number of different sectors (EMPJ, EMPK, EMPL, etc.), with each
> employment sector having a "base" (e.g. EMPJ) and "negative" (e.g.
> EMPJ_neg) forecast scenario.
>
> How can I loop through graphs showing the scenarios for each of the
> (many) employment categories? I can't use "graph combine" as too may
> graphs are displayed and I can't closely examine them. Is there a way I
> could hit the spacebar or Enter key to move to the next graph? And can
> all the grpahs be saved at once in one file?
>
> I tried the following code, but only the final variable, EMPR, is
> displayed:
>
> local empcategories "EMPJ EMPK EMPL EMPM EMPNEMPO EMPP EMPQ EMPR"
> foreach var of local empcategories {
> local graphtitle : variable label `var'
> twoway line `var' `var'_neg Year if Mnemonic==trim("AMSTER")
> }
>
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index