# st: RE: How to drop the entire case from the panel?

 From "Nick Cox" <[email protected]> To <[email protected]> Subject st: RE: How to drop the entire case from the panel? Date Sun, 13 Jul 2003 17:59:22 +0100

```Olena Stavrunova

> > I have a panel data (id and quarters). Could you, please,
> let me know how to
> > delete the entire case, that is all observations for the
> individual if, for
> > example, in at least one quarter variable v1 takes a
> negative value for this
> > individual.
> >

John Hennen

> Try-
> tempvar x y
> gen `x' = v1<0
> egen `y' = max(`x'),by(id)
> drop id if `y' ==1

There is a typo here. John meant

. drop if `y' == 1

You can use expressions as arguments
to many -egen- functions.

So another way to do it might be

. egen nneg = sum(v1 < 0), by(id)
. drop if nneg

Within using any new variables,
you could also

. bysort id (v1) : drop if v1[1] < 0

This is very Stataish. You
sort on -id-

. sort id

and within that you sort on -v1-,
so it is as if you said

. sort id v1

except that you want to do things

. by id:

You can combine the syntaxes:

. bysort id (v1):

After this -sort- if any value
for each -id- is negative, then
the minimum will also be negative,
and that will be first within each
-id-. Hence we can -drop- each -id- if the
first value is negative.

. bysort id (v1) : drop if v1[1] < 0

If the condition was that _all_ values
were negative that would be

. bysort id (v1) : drop if v1[_N] < 0

except that missing values complicate
this. You are better off using some -max()-
function.

Nick
[email protected]

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
```