Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: question


From   May Boggess <mboggess@stata.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: question
Date   Thu, 03 Nov 2005 08:42:03 -0600

On Wednesday Scott asked about missing values with multiple record
survival data:

I am missing data for certain time- variant covariates when t is very small. ...
...for all values of t=0 to t=9, I am missing data for sr. .... assume I wanted to fill in those missing values with the same value as t=10. How would I do this?
The Stata command -stfill- is very useful for replacing
values in covariates of multiple record survival data.
With the option -baseline- it replaces all observations
with the earliest value observed. With the option
-forward- it replaces all missing values with the previous
value observed. This is similar to what Scott needs, but
not exactly: Scott needs to replace missing values with the
next value observed.

We can acheive this with careful sorting and replacing.
I will use the command -gsort- to sort the data
in reverse chronological order and then use -replace-:

clear
input id   time   fail        sr
     1      1      0          .
     1      2      0          .
     1      3      0          .
     1      4      0          .
     1      5      0          .
     1      6      0          .
     1      7      0          .
     1      8      0          .
     1      9      0          .
     1     10      0   .9738716
     1     11      0   1.081043
     1     12      0    1.21261
     1     13      1   1.125889
     2      1      0          .
     2      2      0          .
     2      3      0          .
     2      4      0          .
     2      5      0          .
     2      6      0          .
     2      7      0          .
     2      8      0          .
     2      9      0          .
     2     10      0   .9738716
     2     11      0   1.081043
     2     12      0    1.21261
     2     13      0   1.125889
     2     14      0   1.080463
     2     15      1   .9527455
end
list, sepby(id)
stset time, id(id) fail(fail)
list, sepby(id)
gsort id -_t
replace sr=sr[_n-1] if sr==.
sort id _t
list, sepby(id)


 -- May
mboggess@stata.com


*
*   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/



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