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

st: RE: Reshape question


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: Reshape question
Date   Fri, 24 Oct 2003 14:05:57 +0100

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/



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