Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: problem with looping egen(newvar)=anymatch


From   Ekaterina Hertog <[email protected]>
To   "[email protected]" <[email protected]>
Subject   st: problem with looping egen(newvar)=anymatch
Date   Wed, 20 Jan 2010 22:49:53 +0100

Dear all,
I need to create a binary variable that equals 1 of one of the variables fammem1, fammem2, fammem3, fammem4, … fammem10 equals 2, and 0 otherwise.#I came up with the following solution:
egen fathliv = anymatch(fammem1 fammem2 … fammem10), v(2)
and it seems to work, but I would like to create a loop rather than listing the ten fammem variables individually.
I tried:
forv i=1/10{
egen fathliv = anymatch(fammem`i'), v(2)
}
But this gives me an error message and I am not sure why.
I would be very grateful for advice,
Warm regards,
katya

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   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