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" <[email protected]>
To   <[email protected]>
Subject   Re: st: loop over local list
Date   Tue, 13 Aug 2002 18:15:20 +0100

"Radu Ban" <[email protected]>

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

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

How about

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

... if marstat == 6

[email protected]

*   For searches and help try:

© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index