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

RE: st: creating an array with hospitalization days


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: creating an array with hospitalization days
Date   Tue, 8 Nov 2005 21:24:13 -0000

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 
[email protected] 

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/



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