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]

Re: st: drop observations within groups under certain conditions


From   Nahla Betelmal <nahlaib@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: drop observations within groups under certain conditions
Date   Fri, 28 Jun 2013 14:47:39 +0100

Thank you so much, and thank you Nick for the detailed explanation. I
highly appreciate it.

Nahla

On 28 June 2013 13:58, Richard Goldstein <richgold@ix.netcom.com> wrote:
> I would do this in a couple of steps:
>
> gen byte pos=earnings>0 & earnings<.
> egen byte totpos=total(pos), by(manager_ID)
> keep if totpos>1
> drop totpos pos * unless of course you want to keep these
>
> Rich
>
> On 6/28/13 8:42 AM, Nahla Betelmal wrote:
>> Dear Statalist,
>>
>> my data in focus represnts three variables : manager ID (uniqe(,
>> tenure period (which varies among managers) and earnings (which could
>> be positive, zero, negative, or missing).
>>
>> I want to keep only the managers who have positive earnings at least
>> twice (at least for two years). To be more clear I want to keep all
>> the observations for the manger who has positive earnings at least
>> twice, regardless if in the other years he has non-positive earnings.
>>
>> In other words I want to drop managers who have no positive earnings
>> at all, or positive earnings once during his tenure period.
>>
>> I thought of a command such as : by manager_ID year keep if earnings >
>> 0.  However, this command has two problems: I do not know how to
>> specify "at least twice" occurrence condition (i.e. earning is
>> positive at least twice during manager tenure years) and it  will drop
>> other year-observations for the same manger who has mix range of
>> earnings!
>>
>> For example, I would like to keep all the observation for manager
>> A123, and drop all of those of Manger B567
>>
>>
>> year  manager_ID earnings
>> 1995   A123            + 12
>> 1996   A123            + 4
>> 1997   A123               0
>> 1998   A123              -3
>> 1999   A123               .
>>
>> 1997   B567            + 5
>> 1998   B567             -2
>> 1999   B567              .
>>
>> Thank you
>>
>> Nahla Betelmal
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/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/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index