[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Re: Keeping groups

From   "Michael Blasnik" <>
To   <>
Subject   st: Re: Keeping groups
Date   Sun, 25 May 2008 19:15:22 -0400

Not sure if I understand exactly what you want, but this may do it:

bysort group (nocell): drop if nocell[1]!1 | nocell[_N]!=1

This command will drop all of the observations for any value of group where the value of nocell is not always 1 within that group. The specification of (nocell) as a secondary sort variable will make the smallest value of nocell within each group to be in observation 1 and the largest value to be in observation _N (last one). Therefore, if both those values are equal to 1, then all values of nocell are equal to 1 for that group. If you just wanted to identify these groups rather than drop them, you could change the command to generate a 0/1 variable for the same condition.

Michael Blasnik

----- Original Message ----- From: "David Musselwhite" <>
To: <>
Sent: Sunday, May 25, 2008 2:58 PM
Subject: st: Keeping groups

Dear Listers,

I have a dataset which I've divided into 30000+ groups. The dataset is
quarterly, with observations for each month for each group. What I'm
trying to do is keep those groups in which all cases have the same
value (1) for another variable, called nocell. I'm sure this will be
easy for the advanced users, but I'm stumped, as I'm a new STATA
convert from the world of SAS.

David Musselwhite
Cornell University
*   For searches and help try:

© Copyright 1996–2023 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index