[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

From |
"Nick Cox" <n.j.cox@durham.ac.uk> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
st: RE: RE: Code to generate a difficult variable |

Date |
Thu, 5 Feb 2009 10:35:19 -0000 |

This can be telescoped into bysort Study_id : gen failure = _n == _N & !missing(deathdate) Nick n.j.cox@durham.ac.uk 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. [cpolis@jhsph.edu] 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/

**References**:**st: Code to generate a difficult variable***From:*"Polis, Chelsea B." <cpolis@jhsph.edu>

**st: RE: Code to generate a difficult variable***From:*Howard Lempel <HLempel@brookings.edu>

- Prev by Date:
**st: RE: large numbers in comb(n,k) function: no success** - Next by Date:
**st: RE: Problems in generetaing a variable** - Previous by thread:
**st: RE: Code to generate a difficult variable** - Next by thread:
**st: chi2 test for trend with survey data** - Index(es):

© Copyright 1996–2015 StataCorp LP | Terms of use | Privacy | Contact us | What's new | Site index |