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: drop observations after first occurence of an event
From
Maarten buis <[email protected]>
To
[email protected]
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/