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 at the end of May, and its replacement, statalist.org is already up and running.


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

st: Looping through graphs w/ foreach?


From   "Suran, Luciana @ CBRE EA" <Luciana.Suran@cbre.com>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: Looping through graphs w/ foreach?
Date   Thu, 18 Aug 2011 10:28:27 -0500

Dear Statalist,

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") 
}

Thanks very much,
Lucy


PS - My dataset looks like this:

     |     Year      City        EMPJ    EMPJ_neg |  etc...
     |--------------------------------------------|
117. |   2009.1     AARHUS   13.120725   13.12073 |
118. |   2009.2     AARHUS   12.935554   12.93555 |
119. |   2009.3     AARHUS     12.7599    12.7599 |
120. |   2009.4     AARHUS   12.606806   12.60681 |
121. |   2010.1     AARHUS   12.488331   12.48833 |
     |--------------------------------------------|
122. |   2010.2     AARHUS   12.416534   12.41653 |
123. |   2010.3     AARHUS   12.398641   12.39864 |
124. |   2010.4     AARHUS   12.422541   12.42254 |
125. |   2011.1     AARHUS   12.471289   12.47129 |
126. |   2011.2     AARHUS   12.527941   12.52794 |
     |--------------------------------------------|
127. |   2011.3     AARHUS     12.5789   12.57116 |
128. |   2011.4     AARHUS    12.62395    12.6084 |
129. |   2012.1     AARHUS   12.666225    12.6193 |
130. |   2012.2     AARHUS   12.708856   12.59884 |
131. |   2012.3     AARHUS   12.754306   12.58111 |
     |--------------------------------------------|
132. |   2012.4     AARHUS   12.802356   12.53415 |
283. |   2009.1     AMSTER     71.8408    71.8408 |
284. |   2009.2     AMSTER   71.462831   71.46283 |
285. |   2009.3     AMSTER   70.688815   70.68881 |
286. |   2009.4     AMSTER   69.700475   69.70048 |
     |--------------------------------------------|
287. |   2010.1     AMSTER   68.738197    68.7382 |
288. |   2010.2     AMSTER   68.042369   68.04237 |
289. |   2010.3     AMSTER   67.788478   67.78848 |
290. |   2010.4     AMSTER   67.892409   67.89241 |
291. |   2011.1     AMSTER   68.205148   68.20515 |
     |--------------------------------------------|
292. |   2011.2     AMSTER   68.577681   68.57768 |
293. |   2011.3     AMSTER   68.890762   68.84844 |
294. |   2011.4     AMSTER   69.144223   69.05915 |
295. |   2012.1     AMSTER   69.367668   69.11069 |
296. |   2012.2     AMSTER   69.590696   68.98809 |
     |--------------------------------------------|
297. |   2012.3     AMSTER    69.83484   68.88623 |
298. |   2012.4     AMSTER   70.089351   68.62048 |
      Etc...

*
*   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