Statalist The Stata Listserver


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

Re: st: Simple programming question?


From   "Svend Juul" <[email protected]>
To   <[email protected]>
Subject   Re: st: Simple programming question?
Date   Tue, 17 Oct 2006 23:21:23 +0200

Brad wrote:
 
I have data like the following:
id day1 day2 day3 day4 day5 day6 ... day90
1  0    0    0    1    0    0    ... 0
2  0    0    0    0    1    1    ... .
3  1    1    1    1    1    1    ... 1
4  0    0    0    0    0    0    ... 0
 
Assume that a 1 on day`i' represents failure.  I'm trying to generate a
variable that gives days to failure for survival analysis.  E.g., subject 1
failed on day 4, subject 5 failed on day 5, subject 3 failed on day 1,
subject 4 did not fail and would be considered censored.  90 days worth of
data were collected but not all subjects were observed for the full 90-day
period.  Also note that subjects may be recorded as failing (drinking at
hazardous levels) on any combination of days during the 90-day period.  I'm
trying to calculate number of days to first failure....
---------------------------------------------------------------------
 
In the following example I use only 7 days, but the principle is the same. To find the first day of changed status, examine days in reverse order:
 
clear
input id day1 day2 day3 day4 day5 day6 day7
1  0    0    0    1    0    0    0
2  0    0    0    0    1    1    .
3  1    1    1    1    1    1    1
4  0    0    0    0    0    0    0
5  0    0    .    .    .    .    .
end
 
gen time=7
gen event=0
forvalues I = 7(-1)1 {
  replace time = `I' if day`I'==1
  replace event = 1 if day`I'==1
  replace time = `I'-1 if day`I'>=.
}
list

Hope this helps
Svend
________________________________________________________ 
 
Svend Juul
Institut for Folkesundhed, Afdeling for Epidemiologi
(Institute of Public Health, Department of Epidemiology)
Vennelyst Boulevard 6 
DK-8000 Aarhus C,  Denmark 
Phone, work:  +45 8942 6090 
Phone, home:  +45 8693 7796 
Fax:          +45 8613 1580 
E-mail:       [email protected] 
_________________________________________________________ 

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