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: Looping for STATA graphs using a string variable or a numeric with the labels including in titles
From
Sarah Gerver <[email protected]>
To
"[email protected]" <[email protected]>
Subject
RE: st: Looping for STATA graphs using a string variable or a numeric with the labels including in titles
Date
Fri, 13 Dec 2013 16:05:41 +0000
Thank you so much William - sorted it straight away - I have been staring at this for days!
Sarah
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of William Buchanan
Sent: 13 December 2013 15:47
To: [email protected]
Subject: Re: st: Looping for STATA graphs using a string variable or a numeric with the labels including in titles
A quick guess is that your string variable includes embedded spaces. Do you get the same error when you use compound double quotes around the local macro?
Sent from my iPhone
> On Dec 13, 2013, at 9:34, Sarah Gerver <[email protected]> wrote:
>
> Dear Statalisters,
>
> I am desperately trying to figure out how to produce >130 line graphs on separate figures (i.e. I want >130 graphs). I am trying to create a loop covering all values of a string variable (var_a) which itself is not being plotted.
>
> I have had some success in producing all of the graphs if I encode var_a and use a while loop, however, I cannot figure out how to get the title of the graph to be the string labels on the numeric value. The code I have used is below:
>
> encode var_a, gen(num_var_a)
> local i = 1
> while `i'<=135 {
> line var_b var_c if num_var_a== `i', xlabel(1 2 3 4 5 6 7 8 9 10 11 12
> 13 14 15 16 17 18 19 20 21 22 23, valuelabel angle(90))
> ylab(0(25000)110000) name(gr`i', replace) ytitle(This is my y axis,
> size(small)) xtitle(This is my x axis) title("Tile line 1" "Title line
> 2" "line 3, where I want the label for num_va_a `i'", size(medium)
> color(black)) legend(off) graph save "trust graphs `i'.gph", replace
> local i = `i'+1 }
>
>
> I have also tried the following using the original string for var_a:
>
> levelsof var_a, local(loc_var_a)
> di ` loc_var_a'
> foreach i of local loc_var_a {
> di `i'
> line var_b var_c if var_a == "`i'", xlabel(1 2 3 4 5 6 7 8 9 10 11 12
> 13 14 15 16 17 18 19 20 21 22 23, valuelabel angle(90)) name(gr`i',
> replace) ytitle(Y axis) xtitle(X axis title) title("First line of
> title" "second line of title" "third line: `i'", size(medium)
> color(black)) legend(off)
>
> }
>
> I get the following error (where STG is the first string value of var_a:
>
> STG not found
> r(111);
>
> end of do-file
>
> r(111);
>
> Of note, I also get what appears to be one long string of codes when I first display ` loc_var_a' prior to the foreach loop begins, which might be the issue and why it cannot then find one 3 letter code.
>
> Any ideas on how I get my >130 line graphs with the value of the string code in my graph title so that I know which of the 130+ graphs is which (using either of these loop types or any other coding ideas)?
>
> Many thanks for your help,
>
> Sarah
>
> **********************************************************************
> **** The information contained in the EMail and any attachments is
> confidential and intended solely and for the attention and use of the
> named addressee(s). It may not be disclosed to any other person
> without the express authority of Public Health England, or the
> intended recipient, or both. If you are not the intended recipient,
> you must not disclose, copy, distribute or retain this message or any
> part of it. This footnote also confirms that this EMail has been swept
> for computer viruses by Symantec.Cloud, but please re-sweep any
> attachments before opening or saving. http://www.gov.uk/PHE
> **********************************************************************
> ****
>
> *
> * 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/
*
* 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/
**************************************************************************
The information contained in the EMail and any attachments is confidential and intended solely and for the attention and use of the named addressee(s). It may not be disclosed to any other person without the express authority of Public Health England, or the intended recipient, or both. If you are not the intended recipient, you must not disclose, copy, distribute or retain this message or any part of it. This footnote also confirms that this EMail has been swept for computer viruses by Symantec.Cloud, but please re-sweep any attachments before opening or saving. http://www.gov.uk/PHE
**************************************************************************
*
* 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/