This can be telescoped into
bysort Study_id : gen failure = _n == _N & !missing(deathdate)
Nick
[email protected]
Howard Lempel
I can't test this because I don't currently have access to Stata, but
try the following:
sort Study_id
by Study_id: gen failure = 1 if _n==_N & !missing(deathdate)
replace failure = 0 if failure==.
Polis, Chelsea B. [[email protected]]
I am setting up data for survival analysis on time-to-death. I am using
time-varying covariates, so I have multiple records for each individual.
The column recording my date of death variable was imported such that
the
date repeats in every record, although it will be unnecessary
information
at all rounds except the last. Different women contributed different
numbers
of rounds, ranging from 1 to 8. I'd like to generate a new variable to
indicate failure, such that failure=1 only for the last record for each
individual woman, and only if she has a recorded date of death.
To provide a visual, I have study_id, numrounds, and deathdate,
available,
but would like to write code to be able to generate failure
automatically.
Is this possible? I assume it would have something to do with _n, and
perhaps a foreach command, and an if statement, but I have no idea how
to
actually go about writing this, or figuring it out via help. Any
suggestions?
Study_id numrounds deathdate failure
1 1 03jul2005 0
1 2 03jul2005 0
1 3 03jul2005 0
1 4 03jul2005 1
2 1 . 0
2 2 . 0
2 3 . 0
3 1 15jun2004 1
4 1 . 0
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/