Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


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

st:any easy alternative way when -egen- is not allowed to combine with by


From   Amanda Fu <mandy.fu1@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   st:any easy alternative way when -egen- is not allowed to combine with by
Date   Tue, 21 Dec 2010 17:23:15 -0500

Hi all,

I notice  some options of -egen- are not allowed to combine with by.
I just wondered if there is any good way to handle these situations.

Let me use an example.
----------------------------------------
ID        surveyYear       indicator (maximum value is 10)
1         1985                     0
1         1986                     1
1         1987                     2
2         1985                     0
2         1986                     0
2         1987                     0
...............
----------------------------------------
I want to create a variable "new" that takes value 1 if there is at
least one year for a ID's indicator is above 0  and takes the value 0
(like ID 1) is all the years the indicator is 0 (like ID 2).

What I wish to use is as following:
. bysort id: egen  new=(indicator), anymatch(1/10)

Is there any simple way to do this? Any comments will be helpful. Thank you!

Sincerely,
Amanda Fu
*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index