Statalist


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

st: AW: problem with looping egen(newvar)=anymatch


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

<> 

Because you want to create "fathliv" twice (or rather: 10 times). Say -egen
fathliv`i'-, if you absolutely want this, but you will end up with 10
variables carrying largely redundant information. Why not - egen fathliv =
anymatch(fammem? fammem??), v(2)-?



HTH
Martin

-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von Ekaterina
Hertog
Gesendet: Mittwoch, 20. Januar 2010 22:50
An: [email protected]
Betreff: st: problem with looping egen(newvar)=anymatch

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/


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