Bookmark and Share

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: foreach and levels of string variable


From   Neil Shephard <[email protected]>
To   [email protected]
Subject   Re: st: foreach and levels of string variable
Date   Mon, 27 Sep 2010 10:33:37 +0000

On Mon, Sep 27, 2010 at 10:28 AM, Paul O'Brien <[email protected]> wrote:
> hi,
>
> i have a dataset with results from a number clinical studies of efficacy of emergency contraception and want to test for trend by day's delay in treatment within each study.
>
> using nick cox's FAQ: Is there a way to tell Stata to try all values of a particular variable in a foreach statement without specifying them?
>
> . levelsof study, local(levelstud)
> `"Ashok 2002"' `"Creinin 2006"' `"Ellertson 2003"' `"Fine 2010"' `"Glasier 2010"' `"Hamoda 2004"' `"Ho&Kwan 1993"' `"WHO 19
>> 98"' `"von Hertzen 2002"'
>
> . foreach l of local levelstud {
>  2. ptrend p1 np1 day if study == `l'
>  3. }
> Ashok not found
> r(111);
>
> where am i going wrong?
>

You're missing double quotes around your reference to the local macro
`l'.  Try...

foreach l of local levelstud {
  ptrend p1 np1 day if study == "`l'"
}

Neil


-- 
"One should as a rule, respect public opinion in so far as is
necessary to avoid starvation and to keep out of prison, but anything
that goes beyond this is voluntary submission to an unnecessary
tyranny, and is likely to interfere with happiness in all kinds of
ways..." - Bertrand Russell

Email - [email protected]
Website - http://slack.ser.man.ac.uk/
Photos - http://www.flickr.com/photos/slackline/

*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index