Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


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

RE: st: how drop a block of cases based other variable values


From   Nick Cox <n.j.cox@durham.ac.uk>
To   "'statalist@hsphsun2.harvard.edu'" <statalist@hsphsun2.harvard.edu>
Subject   RE: st: how drop a block of cases based other variable values
Date   Fri, 9 Dec 2011 15:06:39 +0000

If Daniel's values for -winner- are only 1 and missing, then 

bysort r (winner) : drop if winner[1] == 1 

will be sufficient. 

Daniel's own code failed because the -bysort r:- makes no difference to whether -winner==1-. 

But -winner[1]- under -by:- is the first value of -winner- in each group. 

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


-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Maarten Buis
Sent: 09 December 2011 13:53
To: statalist@hsphsun2.harvard.edu
Subject: Re: st: how drop a block of cases based other variable values

On Fri, Dec 9, 2011 at 2:45 PM, Daniel Marcelino wrote:
> can anyone point me how can I drop all observations belonging to
> "r" based on "winner" value? I meant, I don't wish to drop only
> observations where winner values is 1, but
> given I got a winner in "r==a" I want drop all observations of this group.

*------------ begin example --------------
clear
input str2 r byte(w v1 v2 winner)
 "a" .5 1 2  .
 "a" .1 2 3  .
 "a" .9 3 2  1
 "a" .9 3 4  1
 "a" .2 4 5  .
 "a" .3 5 1  .
 "b" .4 1 2  .
 "b" .1 2 3  .
 "b" .7 3 4  .
 "b" .8 4 1  .
 "b" .8 4 5  .
 "b" .9 5 1  .
end

bys r : egen byte todrop = total(winner)
drop if todrop
drop todrop
*------------- end example --------------------


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   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   |   Site index