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   "Maria Montez" <montez@bu.edu>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: creating an array with hospitalization days
Date   Tue, 8 Nov 2005 15:37:12 -0500

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.

Thanks, Maria

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu]On Behalf Of Eric G. Wruck
Sent: Tuesday, November 08, 2005 3:21 PM
To: statalist@hsphsun2.harvard.edu
Subject: Re: st: creating an array with hospitalization days


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.

Eric



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



--

===================================================

       Eric G. Wruck
       Econalytics
       2535 Sherwood Road
       Columbus, OH  43209

       ph:      614.231.5034
       cell:    614.330.8846
       eFax:    614.573.6639
       eMail:   ewruck@econalytics.com
       website: http://www.econalytics.com

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


*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index