Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: loop over local list


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   Re: st: loop over local list
Date   Tue, 13 Aug 2002 18:15:20 +0100

"Radu Ban" <rban@nber.org>

What is wrong with this piece of code (which gives an 'invalid syntax'
error)

local married "0 5"
local single "5 6"
foreach mstat in `mar' `sng'

    tokenize `mstat'
...
keep if marstat > `1' & marstat <= `2'

the last line is the one that produces the error.

What I'm trying to do is make a loop, in which the first run keeps
values of
marstat 1 through 5, and the second run keeps value 6. Is there an
alternative solution? Note that marstat has values 0 to 6 where 0
stands for
'not available', 1-5 are for people who were at some point married and
6 for
people who were never married. I could recode it, but I'll lose
information
that I might need in the future.

>>> What you actually typed is not at all clear to me.

You define locals called -married- and -single-
and then loop over (other?) locals called -mar-
and -sng-?

Where are the braces { }?

It seems you want to do something for
two subsets of the data. It is not clear
why you need to drop the complementary
subset.

How about

... if inrange(marstat,1,5)

... if marstat == 6

Nick
n.j.cox@durham.ac.uk

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   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   |   What's new   |   Site index