gen long id = _n
gen stay = end - begin + 1
expand stay
bysort id : gen day = begin[1] + _n - 1
tab day
Nick
[email protected]
Maria Montez
> you are correct and I'm thinking in SAS but I'm trying really
> hard to switch into STATA!
>
> My problem is that I need to figure out which records
> correspond to overlapping hospitalizations so that I can deal
> with them. I do not want to program case by case because it
> seems to me that I might end up with lots of mistakes. In
> trying to find a mechanical way of doing this I decided that
> I could create an array with the days in the year and then
> add up the arrays corresponding to each patient. At the end
> each patient will have an array and if I have a day that as a
> value greater than 1 than I know that I have potential
> overlaps. I realize this is not the best way.
>
> Ideally I would want to be able to create a variable with day
> and time together because then I could easily just compare
> discharge time in one record is smaller or bigger than
> admission time in the next record. But I couldn't find such function.
Nick Cox
> A quite different issue is that I cannot
> see why you want these 365 extra variables,
> as they add no information to your data.
> What do you want to do with them?
>
> 9 times out of 10 wanting to do this betrays
> a traveller from SAS land who wants to do
> something in a SAS-like way, but I would
> guess happily that you do not need these
> 365 variables at all.
>
> > >Hi! I'm still on v8.
> > >
> > >I'm looking at one year of data for which one record
> > corresponds to one
> > >hospitalization. I created variables day1-day365 to
> > represent all the days
> > >in that year. Now, I would like those variables to be equal
> > to one during
> > an
> > >hospitalization. I have the admission day (admitday) and the
> > discharge day
> > >(disday) and using these, I created two variables begin and
> > end that tell
> > me
> > >when did that hospitalization started and ended. Then I
> > though that I could
> > >loop from begin to end and change the day array from 0 to 1.
> > However I'm
> > >getting a syntax error and I think it comes from the begin and end
> > variables
> > >in the forvalues loop. Can anyone help me?
> > >
> > >sample code:
> > >
> > >forvalues i=1(1)365 {
> > > gen day`i'=0
> > >}
> > >
> > >gen begin=admitday-mdy(10,1,2000)+1
> > >replace begin=1 if begin<=0
> > >
> > >gen end=disday-mdy(10,1,2000)+1
> > >
> > >forvalues i=begin(1)end {
> > > replace day`i'=1
> > >}
> > >
> > >sample data:
> > >
> > >
> > +--------------------------------------------------------------+
> > > | study_id admitday disday begin end
> > day1 day2 |
> > >
> > |--------------------------------------------------------------|
> > > 1. | 19 03jan2001 24jan2001 95 116
> > 0 0 |
> > > 2. | 362 24may2001 29may2001 236 241
> > 0 0 |
> > > 3. | 396 01jun2001 07jun2001 244 250
> > 0 0 |
> > > 4. | 436 21mar2001 22mar2001 172 173
> > 0 0 |
> > > 5. | 438 17jan2001 25jan2001 109 117
> > 0 0 |
> > >
> > |--------------------------------------------------------------|
> > > 6. | 517 06mar2001 21mar2001 157 172
> > 0 0 |
> > > 7. | 517 11sep2001 17sep2001 346 352
> > 0 0 |
> > > 8. | 590 16sep2001 17sep2001 351 352
> > 0 0 |
> > > 9. | 879 20dec2000 22dec2000 81 83
> > 0 0 |
> > >
> > +--------------------------------------------------------------+
*
* 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/