Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: Dates - converting time periods to inividual records


From   "Jonathan Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: Dates - converting time periods to inividual records
Date   Tue, 07 Feb 2006 15:02:48 +0000

David
That works a treat - *many* thanks.

>>> [email protected] 14:58 07/02/06/06 >>>
How's this...?

. list

     +-------------------------------+
     |     start         end   value |
     |-------------------------------|
  1. | 01jan2006   03jan2006       4 |
  2. | 05jan2006   11jan2006       9 |
     +-------------------------------+

. gen id=_n

. gen dur=end-start+1

. expand dur
(8 observations created)

. bysort id: gen date=start+_n-1

. format date %d

. list

     +------------------------------------------------------+
     |     start         end   value   id   dur        date |
     |------------------------------------------------------|
  1. | 01jan2006   03jan2006       4    1     3   01jan2006 |
  2. | 01jan2006   03jan2006       4    1     3   02jan2006 |
  3. | 01jan2006   03jan2006       4    1     3   03jan2006 |
  4. | 05jan2006   11jan2006       9    2     7   05jan2006 |
  5. | 05jan2006   11jan2006       9    2     7   06jan2006 |
     |------------------------------------------------------|
  6. | 05jan2006   11jan2006       9    2     7   07jan2006 |
  7. | 05jan2006   11jan2006       9    2     7   08jan2006 |
  8. | 05jan2006   11jan2006       9    2     7   09jan2006 |
  9. | 05jan2006   11jan2006       9    2     7   10jan2006 |
 10. | 05jan2006   11jan2006       9    2     7   11jan2006 |
     +------------------------------------------------------+
 

-----Original Message-----
From: [email protected] 
[mailto:[email protected]] On Behalf Of Jonathan
Cox
Sent: 07 February 2006 14:44
To: [email protected] 
Subject: st: Dates - converting time periods to inividual records

Greetings,
I'd be grateful for any assistance with the following query regarding
dates in Stata:

Currently I have a dataset with 3 columns: start date of observation;
end date (typically a few days later) of observation; value.  What I
would like to do is turn this into a dataset for individual days - and
assign the value for the time period to each date individually.  I
guess
this is a sort of inverse of the collapse function.

Has anybody come across anything like this before?

Many thanks

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html 
*   http://www.stata.com/support/statalist/faq 
*   http://www.ats.ucla.edu/stat/stata/ 

______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________

______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html 
*   http://www.stata.com/support/statalist/faq 
*   http://www.ats.ucla.edu/stat/stata/
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index