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 help


From   Tina Hernandez-Boussard <boussard@stanford.edu>
To   statalist@hsphsun2.harvard.edu
Subject   st: foreach help
Date   Tue, 18 Dec 2012 10:37:37 -0800

HI All,

I was hoping that someone might help me trouble shoot my foreach loop.  Seems very simple, yet I keep getting an error.  My code is:

. levelsof category , local(levels)
`"allergies"' `"assessment and plan"' `"history of present illness"' `"laboratory results"' `"medications"' `"past medical history
> "' `"physical exam"' `"plan"' `"social history"'

. foreach 1 of local levels {
  2. sum(nonlmct ) if category ==`1'
  3. di r(sum)
  4. }
allergies not found
r(111);


Yet if I run this code outside of the loop I get an the below:

. sum(nonlmct ) if category =="allergies"

    Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
     nonlmct |        72         4.5    2.897303          2         12

. di r(sum)


Any help??

Thanks!

Tina
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index