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 on April 23, and its replacement, statalist.org is already up and running.


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

Re: st: drop observations after first occurence of an event


From   Maarten buis <maartenbuis@yahoo.co.uk>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: drop observations after first occurence of an event
Date   Fri, 19 Feb 2010 05:30:09 -0800 (PST)

--- On Fri, 19/2/10, raoul reulen wrote:
> I want to drop any observations after the first occurrence of 
> an event (coded as 1) 

*------------------ begin example ----------------
drop _all
input id event
1 0
1 0
1 0
1 1
1 0
1 0
2 0
2 0
2 1
2 1
2 0
3 0
3 1
3 0
3 1
end
gen order = _n
bys id (order): gen t  = _n
drop order
bys id (t) : gen sum = sum(event)
bys id (t) : drop if sum > 0 & !(event== 1 & sum== 1)
list, sepby(id)
*------------------- end example ------------------

Hope this helps,
Maarten

--------------------------
Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen
Germany

http://www.maartenbuis.nl
--------------------------


      

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