| |
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
RE: st: Simple programming question?
I'd like to thank all who helped, especially Nick and Svend. I had to adapt
a little to get things just right with my data but the example coding got me
over the hump and I think I've learned a couple of tricks to improve my
future Stata programming in the process. Your gracious assistance is much
appreciated.
Brad
-----Original Message-----
From: [email protected]
[mailto:[email protected]]On Behalf Of Nick Cox
Sent: Wednesday, October 18, 2006 6:34 AM
To: [email protected]
Subject: RE: st: Simple programming question?
If anyone is confused, Brad's question was
"I'm trying to calculate number of days to first failure."
Failure I understand to be coded by 1.
I was focusing on that question and that alone.
Svend's code says
If there is no failure (values are 0 or missing),
the time of first failure is deemed to be the last day
with a non-missing value. And -event- is coded 0
correspondingly.
My code says,
If there is no failure, the time of failure is returned
as missing.
All I know about processing survival data can be written
in one corner of a Kaplan-Meier plot, so I yield to Svend
as evidently this is how survival people do it.
Nick
[email protected]
Svend Juul
> 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
>
*
* 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/