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]

st: RE: re: data row transformation for irregular consecutive days


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: re: data row transformation for irregular consecutive days
Date   Mon, 22 Feb 2010 16:39:05 -0000

Thanks to Kit for the mention. For some Stata logic on working with
spells, see

SJ-7-2  dm0029  . . . . . . . . . . . . . . Speaking Stata: Identifying
spells
        . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  N.
J. Cox
        Q2/07   SJ 7(2):249--265                                 (no
commands)
        shows how to handle spells with complete control over
        spell specification

Nick 
[email protected] 

Kit Baum

Kaspar said

Is there a fast way in Stata 11 to do this data transformation?

What I have:
symbol	days
AAL	04-10-2004
AAL	10-01-2005
AAL	11-01-2005
AAL	12-01-2005
AAL	01-04-2005
AAL	04-04-2005
AAL	06-06-2005
AAL	07-06-2005
AAL	08-06-2005

What I need:
AAL	04-10-2004 04-10-2004
AAL	10-01-2005 12-01-2005
AAL	01-04-2005 01-04-2005
AAL	04-04-2005 04-04-2005
AAL	06-06-2005 08-06-2005


g date = date(var2,"DMY")
g en = _n
tsset en
// requires N J Cox -tsspell- from SSC (findit tsspell)
tsspell date, fcond(D.date>1)
bys _spell: g sdate = date if _seq==1
bys _spell: g ndate = date if _end
l
collapse sdate ndate, by(var1 _spell)
format sdate %td
format ndate %td
l

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