Statalist


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

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


From   "Martin Weiss" <[email protected]>
To   <[email protected]>
Subject   AW: st: RE: Looping over values of a string variable to create twoways
Date   Wed, 30 Sep 2009 22:37:50 +0200

<> 

" Adding the display command solved all of my
problems"


Did it? That would be a "first". Still, if it works for you... 


HTH
Martin

-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von Dorothy Bridges
Gesendet: Mittwoch, 30. September 2009 21:07
An: [email protected]
Betreff: Re: st: RE: Looping over values of a string variable to create
twoways

Martin,

Thank you for your help.  Adding the display command solved all of my
problems (though I can't say I understand why) --

Thanks again,
Dorothy

On Wed, Sep 30, 2009 at 2:58 PM, Martin Weiss <[email protected]> wrote:
>
> <>
>
> Inn  addition to my earlier post, note that it is not a good idea to name
> the -graph- according to the string variable you are conditioning on.
> Comment in the fourth string in this example to see that this causes
> problems:
>
> **************
> clear*
>
> input str10 mystr
> "here"
> "there"
> "everywhere"
> //"Allentown-Easton"
> end
>
> compress
>
> expand 10
>
> gen x =_n
> gen y=rnormal()
>
>
> levelsof mystr, local(str)
>
> foreach lev of local str{
>        tw (line y x if mystr=="`lev'"), /*
>        */ name("`lev'", replace)
> }
> **************
>
>
> HTH
> Martin
>
>
> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]] On Behalf Of Dorothy Bridges
> Sent: Mittwoch, 30. September 2009 19:52
> To: [email protected]
> Subject: st: Looping over values of a string variable to create twoways
>
> 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."
>
> I seached the archives and did find a similar query, but I still could
> not solve my problem.
>
> Thanks,
> Dorothy
> *
> *   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/
>

*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index