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

st: RE: RE: Reshape question


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

This leaves open the question of what 
to do if these dates are just strings. 

One solution looks like this: 

gen date2 = ym(year(date("1 " + bclmeddt, "dmy", 2040)), 
               month(date("1 " + bclmeddt, "dmy", 2040))) 

Is there a more direct way to do it? 

Nick 
[email protected] 

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

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