[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
st: RE: Help with elapsed time
> 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]
* For searches and help try: