Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

st: RE: repeated measures


From   Nick Cox <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   st: RE: repeated measures
Date   Tue, 7 Sep 2010 21:07:15 +0100

The more difficult part of this is an FAQ, as at 

FAQ     . . . . . . . . . . . . . . . . . . . . . . . Replacing missing values
        2/03    How can I replace missing values with previous or
                following nonmissing values?
                http://www.stata.com/support/faqs/data/missing.html

The easier part of this is an application of -by()-, as at 

SJ-2-1  pr0004  . . . . . . . . . . Speaking Stata:  How to move step by: step
        Q1/02   SJ 2(1):86--102                                  (no commands)
        explains the use of the by varlist : construct to tackle
        a variety of problems with group structure, ranging from
        simple calculations for each of several groups to more
        advanced manipulations that use the built-in _n and _N

To copy lab results backward in time, try this

gen negvisitdate = - visitdate 
bysort patient (negvisitdate) : replace sbp = sbp[_n-1] if missing(sbp) 
bysort patient (negvisitdate) : replace dm = dm[_n-1] if missing(dm)
bysort patient (negvisitdate) : replace glu = glu[_n-1] if missing(glu)

Now 

drop negvisitdate 
bysort patient (visitdate) : keep if _n == 1 

Alternatively, David Kantor has a utility -carryforward- at SSC. But something like the code here should suffice if your example is indicative. 

Nick 
[email protected] 

Michael Eisenberg

I have a problem I hope you can help with that involves cleaning a
dataset for analysis.

I have a dataset with about 10K men.  Several men had multiple clinic
visits, so that there are about 12K observations.  There is also some
lab data that I'll need that was not obtained until follow up visits.

I would like to only analyze data from the earliest visit and the
first available lab data.

Can stata do this?


Turn this

patient     visitdate    sbp       dm          glu
1              1/1/09       140       .             .
1              1/4/09       128       .            202
1              2/1/09       131      1            .

2              4/1/09       160      .             341
2              4/4/09       144       .            180
2              5/1/09       170      1            .

3              6/1/09       119       .             .
3              6/4/09       107       .            .
3              7/1/09       124      .            96

4              9/1/09       104       1          110
4              9/4/09       155       .            .
4             10/1/09       .         .              .

Into this

patient     visitdate    sbp       dm          glu
1              1/1/09       140      1             202
2              4/1/09       160      1            341
3              6/1/09       119       .            96
3              9/1/09       104      1            110


*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index