Statalist


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

Re: st: Looping over values of a string variable to create twoways


From   Dorothy Bridges <dbstata@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Looping over values of a string variable to create twoways
Date   Wed, 30 Sep 2009 15:07:34 -0400

I see, thank you!

On Wed, Sep 30, 2009 at 3:05 PM, Scott Merryman
<scott.merryman@gmail.com> wrote:
> On Wed, Sep 30, 2009 at 12:52 PM, Dorothy Bridges <dbstata@gmail.com> wrote:
>> Hi everyone:  I would like to write a foreach loop that will produce a
>> separate twoway graph for each value of my string variable msa_name.
>>
>> When I enter:
>>
>> levels msa_name, local(MSA)
>> foreach i of local MSA {
>> #delimit;
>> twoway (line yvar1 xvar if msa_name==`i' & state1==1, lpattern(dash))
>> (line yvar2 xvar if msa_name==`i' & state1==1, color(navy) yaxis(2)),
>> title("`i'",color(black) placement(west) justification(left))
>> legend(off)
>> saving(`i', replace);
>> };
>>
>> Stata tells me, "end of do file," but does nothing.
>>
>> In an attempt to isolate the problem, I tried the simpler:
>>
>> foreach i of local MSA {
>> twoway line yvar1 xvar if msa_name==`i' & state1==1 & county1==1, lpattern(dash)
>> }
>>
>> which returns, "Allentown not found."  The first value of msa_name is
>> "Allentown-Easton."
>>
>
> You need to bind the local `i' in double quotes.  As you have written
> it,  msa_name==`i'  will resolve to  msa_name== Allentown-Easton.
>
> Also in your code, the option -saving(`i', replace)- will not work
> with names that contain hyphens.
>
> Scott
>
> *
> *   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/
>

*
*   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   |   What's new   |   Site index