Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

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


From   Amanda Fu <[email protected]>
To   [email protected]
Subject   Re: st:any easy alternative way when -egen- is not allowed to combine with by
Date   Tue, 21 Dec 2010 17:50:16 -0500

Just a supplement to my question:

I know I could create an intermediate variable as following:

bysort id: g  sumnew=sum(indicator)
bysort id: g  new=(sumnew>0,1,0)

But I do not like this way because of the intermediate variable
"sumnew". It is created for the purpose of getting "new". If I keep
it, it will not be useful in the analysis; if I drop it, what if I
want to check if "new" is correct or not ?

I am looking forward to hearing how you deal with this kind of
intermediate variables. Thank you!

Amanda Fu
On Tue, Dec 21, 2010 at 5:23 PM, Amanda Fu <[email protected]> wrote:
> 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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index