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   Wed, 18 Oct 2006 13:00:45 +0200

Nick wrote:

Svend's technique is nice, but doesn't 
produce the right answer if the event
never occurs. In that case -time- is 
initialised to 7, and never changed. 

A fix -- which by a interesting programming law 
also yields shorter code -- is to initialise 
-time- as missing. 

 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= . 
 gen event=0
 forvalues I = 7(-1)1 {
   replace time = `I' if day`I'==1
   replace event = 1 if day`I'==1
 }
 list
-------------------------------------------------

I don't fully agree: In the fifth observation my technique
sets time to 2 and event to 0 (censoring), Nick's sets it to 
missing despite the knowledge that the subject survived 
at least two days. But when all time information is missing,
the result should be missing, of course. This calls for a 
slightly more, not less, complex series of commands:

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'>=.
}
recode time(0=.)
list

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: +45 8942 6090
Home:  +45 8693 7796
Email: [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