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

st: RE: Help with elapsed time


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: Help with elapsed time
Date   Mon, 16 Jun 2003 13:44:24 +0100

Eric Hixson
 
> I would like to calculate the interval between 
> hospitalizations for unique individuals.  My data is set up 
> as follows:
> 
> pat_id	admit_dt		disch_dt		order
> 1	5/6/2002		5/9/2002		1
> 1	7/1/2002		7/7/2002		2
> 2	3/21/2002	3/31/2002	1
> 2	4/9/2002		4/12/2002	2
> 3	10/16/2002	10/25/2002	1
> 4	11/1/2002	11/4/2002	1
> 4	12/15/2002	12/23/2002	2
> :
> :
> 
> The field pat_id represents unique individuals.  I 
> successfully ranked admissions using by pat_id: egen order 
> = rank(disch_dt) but now want to calculate the day interval 
> between admissions for each pat_id (admit_dt [visit 2] - 
> disch_dt [visit 1]).
> 
> First hospitalizations will have no interval and cases 
> where there is only a single admission like pat_id #3 will 
> also have no interval because they had no readmission.
> 
> I am sure this is an easy fix but am stumped.  Any help is 
> greatly appreciated.

Note that -egen, rank()- may in principle produce tied 
ranks, i.e. if an individual were admitted and 
discharged and then re-admitted on the same day. 

However, the interval can, and should, be calculated 
separately from your ranking. Assuming that your 
dates are proper Stata dates, 

. bysort id (admin_dt) : gen interval = admin_dt - disch_dt[_n-1] 

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