<>
**********
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" <[email protected]>
To: <[email protected]>
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/