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

From |
"Maria Montez" <montez@bu.edu> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
RE: st: creating an array with hospitalization days |

Date |
Tue, 8 Nov 2005 17:40:18 -0500 |

Nick, 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. I really didn't want to bother you with all this but I just got stuck. Thanks, Maria -----Original Message----- From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu]On Behalf Of Nick Cox Sent: Tuesday, November 08, 2005 4:24 PM To: statalist@hsphsun2.harvard.edu Subject: RE: st: creating an array with hospitalization days You are right. begin(1)end doesn't qualify, by a long way, as a range acceptable to -forval-. Stata has to be able to work out, immediately, what number you mean by "begin" and what by "end". Also, what goes in those positions _must_ be constants. They cannot be variables. 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. Nick n.j.cox@durham.ac.uk Maria Montez > Here is the error message: > > . forvalues i=begin(1)end { > 2. replace day`i'=1 > 3. } > invalid syntax > r(198); > > I actually tabulated both begin and end and begin goes from > 1-364 and end > goes from 1-365. I think I cannot use variables in defining > where the loop > should start and end. I did a test by writing > > forvalues i=begin(1)end { > replace day5=1 > } > > and I get the same error. Eric G. Wruck > What was the syntax error? You may have gone past the 365th > element of your > array if you have a discharge day sometime past 1-October-2001, or > thereabouts. > >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/

`<<attachment: winmail.dat>>`

**References**:**RE: st: creating an array with hospitalization days***From:*"Nick Cox" <n.j.cox@durham.ac.uk>

- Prev by Date:
**RE: st: Please help me (urgent)** - Next by Date:
**RE: st: creating an array with hospitalization days** - Previous by thread:
**RE: st: creating an array with hospitalization days** - Next by thread:
**RE: st: creating an array with hospitalization days** - Index(es):

© Copyright 1996–2017 StataCorp LLC | Terms of use | Privacy | Contact us | What's new | Site index |