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: forvalues


From   - <[email protected]>
To   [email protected]
Subject   st: forvalues
Date   Tue, 23 Oct 2012 13:04:29 +0100

hello all,
I'm trying to build a simple loop, and have looked at Help for
"foreach" and "forvalues", but can't get it to work. I just want to
set a variable i to take consecutive values from 1 to 53, so use
forvalues i=1/53, then give its value to a variable in my data called
"single" (refers to the number of samples for each person) which has
integer values ranging from 1 to 53, and create tables of statistics
for age in men and women. So there would be 53 tables of ages, one for
each number of samples, summarized by sex.
Haven't use loops in stata before, I write:

forvalues i = 1/53 {
  2. tabstat age if(single=='i'), by(sexcat) stats(mean sd n min max
median p10 p25 p75 p90)
  3. }

but the message is that 'i' is an invalid name. If I use
if(single==i), it says "i not found". Can anyone tell me what I'm
doing wrong?

Thank you all
*
*   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