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

st: RE: Help with elapsed time


From   "Eric Hixson" <[email protected]>
To   [email protected]
Subject   st: RE: Help with elapsed time
Date   Mon, 16 Jun 2003 17:13:43 -0400

A simple and effective solution - as usual.
Thanks Nick.

>>> [email protected] 06/16/2003 8:44:24 AM >>>
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/ 



------------------------------------------------------------------------------
Confidentiality Note:  This message is intended for use only by the individual or entity to which it is addressed and may contain information that is privileged, confidential, and exempt from disclosure under applicable law.  If the reader of this message is not the intended recipient or the employee or agent responsible for delivering the message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited.  If you have received this communication in error,  please contact the sender immediately and destroy the material in its entirety, whether electronic or hard copy.  Thank you.
==============================================================================


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