Statalist


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

st: Converting span data to spell data


From   John-Paul Ferguson <[email protected]>
To   [email protected]
Subject   st: Converting span data to spell data
Date   Tue, 27 Nov 2007 23:13:54 -0500

Hello,

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?

Best Regards,
John-Paul Ferguson
MIT
*
*   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