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


From   "Paul O'Brien" <paul.obrien@afe2.org.uk>
To   statalist <statalist@hsphsun2.harvard.edu>
Subject   st: foreach and levels of string variable
Date   Mon, 27 Sep 2010 11:28:59 +0100

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?



thanks,

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