Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[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 <[email protected]>
To   "'[email protected]'" <[email protected]>
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 
[email protected] 


-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Maarten Buis
Sent: 09 December 2011 13:53
To: [email protected]
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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index