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]

st: re: data row transformation for irregular consecutive days


From   Kit Baum <baum@bc.edu>
To   statalist@hsphsun2.harvard.edu
Subject   st: re: data row transformation for irregular consecutive days
Date   Mon, 22 Feb 2010 11:03:51 -0500

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


Kit Baum   |   Boston College Economics & DIW Berlin   |   http://ideas.repec.org/e/pba1.html
                              An Introduction to Stata Programming  |   http://www.stata-press.com/books/isp.html
   An Introduction to Modern Econometrics Using Stata  |   http://www.stata-press.com/books/imeus.html


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