Statalist The Stata Listserver


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

st: merging spell data to episode data


From   "Amanda Kowalski" <[email protected]>
To   <[email protected]>
Subject   st: merging spell data to episode data
Date   Wed, 12 Jul 2006 10:38:40 -0400

Statalist,

I am trying to merge spell data to episode data.  For example, my spell data
looks something like this (with dates formatted as dates in Stata):

id 	startd 	endd			othervars
1	jan1,2006	mar15,2006		5
1	mar16,2006	jun1,2006		13
1	jun2,2006	mar1,2007		7
2	feb7,2006	mar3,2006		6
2	jun4,2006	sep5,2006		6

(None of the spells overlap, but there are gaps).

And my episode data looks somthing like this:

id	date		otherstuff
1	feb1,2006	7
1	feb2,2007	8
2	mar3,2006	3

For each episode, I'd like to merge on the data from the spell that covers
it.  Ideally, there would be a merging rule that would merge by id if date
is in the range specified by startd and endd, but I can't find any commands
that do this.

I have searched the stata help files, the internet, and the statlist
archives.  Do you have any suggestions?  My inelegant ideas include:

Turn the spell data into date data by making one observation for every date,
retaining startd and endd with every observation, and then merge.  This
isn't a good plan because my dataset is very large.

Use "joinby" to merge every pairwise combination of observations by id.
Then, if date isn't between startd and endd, discard the observation.
However, I'd prefer to retain unmatched spells and episodes, and this
strategy would make it harder to locate them.

Any suggestions?

Thanks,
Amanda




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