Bookmark and Share

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

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

st: drop observations within groups under certain conditions

From   Nahla Betelmal <>
Subject   st: drop observations within groups under certain conditions
Date   Fri, 28 Jun 2013 13:42:13 +0100

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

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:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index