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

From |
Howard Lempel <HLempel@brookings.edu> |

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

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

Date |
Thu, 5 Feb 2009 01:02:01 -0500 |

Chelsea, 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==. Hope this helps. Howie ________________________________________ From: owner-statalist@hsphsun2.harvard.edu [owner-statalist@hsphsun2.harvard.edu] On Behalf Of Polis, Chelsea B. [cpolis@jhsph.edu] Sent: Wednesday, February 04, 2009 10:30 PM To: statalist@hsphsun2.harvard.edu Subject: st: Code to generate a difficult variable Dear Statalisters, 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 Many thanks! Chelsea Polis * * 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/ * * 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/

**Follow-Ups**:**st: RE: RE: Code to generate a difficult variable***From:*"Nick Cox" <n.j.cox@durham.ac.uk>

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

- Prev by Date:
**st: Code to generate a difficult variable** - Next by Date:
**RE: st: time efficient way to choose variables** - Previous by thread:
**st: Code to generate a difficult variable** - Next by thread:
**st: RE: RE: Code to generate a difficult variable** - Index(es):

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