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

st: levels for varlist?


From   "Danielle H. Ferry" <[email protected]>
To   StataList <[email protected]>
Subject   st: levels for varlist?
Date   Tue, 23 Sep 2003 10:43:24 -0400

Hi,

Is there a command similar to -levels- that works across a varlist?
Specifically, suppose I have the variables highrisk1, highrisk2, lowrisk1,
lowrisk2, lowrisk3. I want to write a program with a loop that does
something when highrisk==1, then when highrisk2==1, then when lowrisk1==1,
then when lowrisk2==1, and finally when lowrisk3==1. For example:

-----------------------------
program define example

    forval i = 1(1)2 {
     ta year if `1'`i'==1
    }

end

example highrisk
example lowrisk
-----------------------------

Since there are 2 highrisk variables and 3 lowrisk variables, the way I've
written it, this will miss tabulating when lowrisk3==1. If I make the second
line: "forval i = 1(1)3 {" then Stata will object when it gets to
"highrisk3==1" since highrisk3 doesn't exist. Something similar to -levels-
would enable Stata to figure out what the max on `i' should be.

Thanks.

-- 
Danielle H. Ferry
National Bureau of Economic Research
365 Fifth Avenue, 5th Floor
New York, NY 10016
*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index