Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

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

st: foreach and levels of string variable

From   "Paul O'Brien" <>
To   statalist <>
Subject   st: foreach and levels of string variable
Date   Mon, 27 Sep 2010 11:28:59 +0100


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

where am i going wrong?


*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index