|
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
st: Re: Keeping groups
..
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" <[email protected]>
To: <[email protected]>
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.
Thanks,
David Musselwhite
Cornell University
*
* 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/