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: drop observations within groups under certain conditions


From   Nahla Betelmal <[email protected]>
To   [email protected]
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 <[email protected]> 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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index