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

From |
"Nick Cox" <n.j.cox@durham.ac.uk> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
st: RE: Converting span data to spell data |

Date |
Wed, 28 Nov 2007 11:26:31 -0000 |

With your well-behaved example data, this is sufficient. gen duration = end - start + 1 expand duration bysort id (start) : gen period = _n N.B. sorry about your cold, but it's summer for an important fraction of the list! John-Paul Ferguson I am struggling with converting panel data from one form to another. The current data structure does not seem to lend itself to a simple reshape. I am also struggling with the first wave of the winter colds and flus, which may be why the solution is eluding me. I'd greatly appreciate ideas anyone has on the following problem. Presume I have data in the following form: id start end true a 1 4 1 a 5 6 0 a 7 10 1 a 11 13 0 a 14 16 1 b 1 3 1 b 4 7 0 b 8 10 1 I would like to put it in this form: id period true a 1 1 a 2 1 a 3 1 a 4 1 a 5 0 a 6 0 a 7 1 a 8 1 a 9 1 a 10 1 a 11 0 a 12 0 a 13 0 a 14 1 a 15 1 a 16 1 b 1 1 b 2 1 b 3 1 b 4 0 b 5 0 ...and so on. This isn't quite the same as running reshape on the data, because the data are not, technically, in a wide format. I suspect I am not the first person to encounter this issue: I have data that reports spans of time when some condition holds, and I want to convert the data into spells. Is there a canned command, or a canny combination of reshape and some other commands, that will do this? * * 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/

**Follow-Ups**:**Re: st: RE: Converting span data to spell data***From:*John-Paul Ferguson <jpferg@MIT.EDU>

**References**:**st: Converting span data to spell data***From:*John-Paul Ferguson <jpferg@MIT.EDU>

- Prev by Date:
**st: bugfix hangroot** - Next by Date:
**Re: st: RE: Converting span data to spell data** - Previous by thread:
**st: __0000004 already defined - error?** - Next by thread:
**Re: st: RE: Converting span data to spell data** - Index(es):

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