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: combining consecutive similar observations in time series datasets
From
Jeph Herrin <[email protected]>
To
[email protected]
Subject
Re: st: combining consecutive similar observations in time series datasets
Date
Mon, 18 Mar 2013 10:09:25 -0400
You don't indicate if you need to worry about gaps. If not, then this will work:
bys id coded (start) : egen newstart=start[1]
bys id coded (end) : egen newend = end[_N]
bys id coded : keep if _n==1
Or, if you really don't have any other variables
collapse (min) start (max) end, by(id coded)
will work.
On 3/18/2013 2:51 AM, Adeel Yousaf wrote:
Hi,
how can I combine multiple rows of an activity to one row and generate
its start and end time, in panel dataset, if the activity occurs
adjacently. For example, in the first table 1 the activity code "11"
has 3 rows from 4:00 am to 5:30am, I need to get its compact form
shown in second table :-
actual dataset:-
id start end coded
100003 4:00 4:30 11
100003 4:30 5:00 11
100003 5:00 5:30 11
100003 5:30 5:45 13
100003 5:45 6:00 14
100003 6:00 6:30 14
100003 6:30 7:00 14
100003 7:00 7:15 15
100003 7:15 7:30 16
100003 7:30 8:00 16
100003 8:00 8:15 16
100003 8:15 8:30 17
100003 8:30 8:45 15
100003 8:45 9:00 15
100003 9:00 9:30 15
100003 9:30 10:00 15
what i need is:-
id start end coded
100003 4:00 5:30 11
100003 5:30 5:45 13
100003 5:45 7:00 14
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/