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]

st: foreach help


From   Tina Hernandez-Boussard <[email protected]>
To   [email protected]
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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index