Statalist


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

RE: st: Re: Keeping groups


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: Re: Keeping groups
Date   Mon, 26 May 2008 17:25:22 +0100

The complement to Michael's command is also of interest: 

bysort group (nocell) : keep if nocell[1] == 1 & nocell[_N] == 1 

The related problems of identifying which groups are homogeneous for
some command <whatever> (any values acceptable as constants) is solved
by 

bysort group (nocell) : <whatever> if nocell[1] == nocell[_N] 

and which are heterogeneous is solved by 

bysort group (nocell) : <whatever> if nocell[1] != nocell[_N]

There is an FAQ on the last at 

FAQ     . . . . . .  Listing observations in a group that differ on a
variable
        11/01   How do I list observations in a group that differ
                on a variable?
                http://www.stata.com/support/faqs/data/diff.html

Nick
n.j.cox@durham.ac.uk 

Joseph Coveney

Michael Blasnik wrote (excerpted):

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

------------------------------------------------------------------------
--------

Just a typo in Michael's suggestion:

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

Bracketing operators with spaces makes them more visible, and it seems
that
the code is then is a bit easier to decipher and that it's somewhat
easier
to spot coding errors.  I believe that Stata handles white space around
operators similarly to how SAS does, so that you should be able to keep
your
preference as far as this goes when coming to Stata from SAS.


*
*   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/



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