Statalist


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

st: Code to generate a difficult variable


From   "Polis, Chelsea B." <[email protected]>
To   "[email protected]" <[email protected]>
Subject   st: Code to generate a difficult variable
Date   Wed, 4 Feb 2009 22:30:39 -0500

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/



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