I think I have a fairly simple loop question that I can't seem to get my
head around.
I have a series of variables, say x1-x30, that correspond to months in a
program (a value of 1 indicates a person was present in the program in a
given month). I simply want to find the first month a person shows up.
I tried the following, but it's not working and I'm not sure why.
gen FirstContact = .
local i = 0
while FirstContact == . {
local i = `i' + 1
replace FirstContact = `i' if x`i' == 1
}
The code runs without error, but does not find the correct first month
someone shows up. For example, in one case I have:
x1 = ., x2 = 1, x3 = 1, x4 = 1, x5 = 1, x6 = 1, ... and it returns
FirstContact = 5.
Any thoughts on how to make this code work or better code are much
appreciated.
Thanks,
Shawn
*
* 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/