Statalist


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

st: Re: Turning an observation with start and end dates into a time series


From   "Martin Weiss" <martin.weiss1@gmx.de>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: Re: Turning an observation with start and end dates into a time series
Date   Sun, 31 May 2009 22:53:58 +0200

<>

**********
clear*

input   ID   var1 /*
*/  var2   start   end
1     3        4   /*
*/    6        8
2     4        3    /*
*/  7        9
3 3 1 4 9
end

list, sepby(ID) noobs

qui{
gen diff=end-start+1
expand diff
bys ID: replace/*
*/ start=start+_n-1
drop end diff
rename start date
}
list, sepby(ID) noobs
**********

HTH
Martin
_______________________
----- Original Message ----- From: "Malcolm Wardlaw" <malcolm@mail.utexas.edu>
To: <statalist@hsphsun2.harvard.edu>
Sent: Sunday, May 31, 2009 10:02 PM
Subject: st: Turning an observation with start and end dates into a time series


I have a quick question about the best practice for forming a time
series from an observation with a start and end date.  I have a couple
of ways that I do it, either with -reshape- or -expand- and then using
various fills, but they seem too much like inelegant hacks.

Specifically, lets say I have a list of observations that contain:
ID   var1   var2   start   end
1     3        4       6        8
2     4        3       7        9

I want to turn it into the following:
ID   var1   var2   date
1     3        4        6
1     3        4        7
1     3        4        8
2     4        3        7
2     4        3        8
2     4        3        9

Is there a best practice way to do this?
*
*   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/


*
*   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   |   What's new   |   Site index