Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: RE: Reshape question (managing elapsed date)


From   "Joao Pedro W. de Azevedo" <[email protected]>
To   <[email protected]>
Subject   st: RE: RE: Reshape question (managing elapsed date)
Date   Fri, 24 Oct 2003 17:45:41 +0100

Many thanks for your help.
I have another question.
The format of my date variable is elapsed date.  
As an approximation I'm using 30.5 as my average month, however I would like
to be more precise.
I would like to know if any one could suggest me any procedure to increase
the acuracy of this process. 


. preserve
. gen diff = 1+round((bclmeddt- bclmstdt)/30.5) 
. expand diff
. bysort serial : replace bclmsdt = bclmsdt[_n-1] + 1 if _n > 1
. tab serial bclmsdt
. save expanded
. restore

All the best,
Joao Pedro

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Nick Cox
Sent: Friday, October 24, 2003 2:06 PM
To: [email protected]
Subject: st: RE: Reshape question


Joao Pedro W. de Azevedo

> I'm trying to generate a new dataset and I would sincerely
> appreciate
> suggestions or how to approach the problem.
> I have records on individuals start and end date on a
> program participation
> on a long format (table 1) and I'm trying to reshape it to
> a wide format in
> order to generate a table similar to TABLE 2. Table 2 takes
> the value of one
> for the monthly intervals encompassed between the start and end date
> available on tabe 1 and zero for the remaining periods.
>
> TABLE 1
>
> serial	bclmstdt	bclmeddt
> 2	May 99	Jul 99
> 20	Jul 99	Nov 99
> 23	Aug 99	Feb 00
> 26	Oct 99	Dec 99
> 30	May 99	Jun 99
> 30	Dec 99	Feb 00
>
>
> TABLE 2
> Serial May-99	Jun-99	Jul-99	Aug-99	Sep-99	Oct-99	Nov-99	Dec-99
> Jan-00	Feb-00
> 2	1	1	1	0	0	0	0
> 0	0
> 20	1	1	1	1	1	1	0
> 0	0
> 23	0	0	1	1	1	1	1
> 1	1
> 26	0	0	0	0	1	1	1
> 0	0
> 30	1	1	0	0	0	0	1
> 1	1
>
> I would sincerely appreciate if you could help me on this.
>

No doubt -reshape- could be used here but a different
approach springs to mind. The reason is important: even if
you got to a wide structure in which each month is a variable,
what would you use to tabulate those variables? (There is
an answer to this!)

I assume that underneath the format these are really
Stata monthly dates.

. l

     +-----------------------------+
     | serial   bclmsdt   bclmeddt |
     |-----------------------------|
  1. |      2    May 99     Jul 99 |
  2. |     20    Jul 99     Nov 99 |
  3. |     23    Aug 99     Feb 00 |
  4. |     26    Oct 99     Dec 99 |
  5. |     30    May 99     Jun 99 |
     |-----------------------------|
  6. |     30    Dec 99     Feb 00 |
     +-----------------------------+

. preserve
. gen diff = bclmeddt - bclmsdt
. expand diff
. bysort serial : replace bclmsdt = bclmsdt[_n-1] + 1 if _n > 1
. tab serial bclmsdt
. save expanded
. restore

Nick
[email protected]

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