Statalist


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

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


From   Ekaterina Hertog <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: AW: AW: problem with looping egen(newvar)=anymatch
Date   Thu, 21 Jan 2010 17:20:42 +0100

Dear Martin and Nick,
Thank you very much for the very detailed advice!
warm regards,
Ekaterina

Martin Weiss wrote:
<>
The specification of your -varlist- fed to -anymatch- may well matter, if
you have additional "fammem"s lying around which you do not want to check
for value 2. Note the difference in this example, as evident from the
-notes- -list-ed at the end, which -egen- helpfully leaves behind...


*************
clear*
set obs 10000
//create data
foreach var of newlist fammem1-fammem30{
gen byte `var'= irecode(runiform(),0,.2,.5,.7) }

egen fathliv =anymatch(fammem? fammem??), v(2)
egen evenbetterfathliv =anymatch(fammem? fammem10), v(2)
note list
*************



HTH
Martin


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


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


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


--
Ekaterina Hertog (née Korobtseva)
Career Development Fellow
Department of Sociology and Nissan Institute of Japanese Studies
University of Oxford

27 Winchester Road
Oxford
OX2 6NA
United Kingdom


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