Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down on April 23, and its replacement, **statalist.org** is already up and running.

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

From |
Morten Hesse <mh@crf.au.dk> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: RE: repeated measures |

Date |
Wed, 08 Sep 2010 09:52:18 +0200 |

that the file with multiple observations turn into a panel. If you have: ID YEAR HOSPITALIZATION 1 1995 1 1 1997 1 1 1997 1 1 1998 1 2 1995 1

And you want a panel with years nested within individuals, so that: ID YEAR HOSPITALIZATION 1 1995 1 1 1996 0 1 1997 2 1 1998 1 2 1995 1 2 1996 0 2 1997 0 2 1998 0

Best regards Morten Den 07-09-2010 22:36, Nick Cox skrev:

Excellent. He needs the dates as well, which is easy too. Nick n.j.cox@durham.ac.uk David Bell Or maybe simpler: collapse (first) sbp dm glu, by(patient) On Sep 7, 2010, at 4:07 PM, Nick Cox wrote: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 n.j.cox@durham.ac.uk 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/

* * 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**:**Re: st: RE: repeated measures***From:*Morten Hesse <mh@crf.au.dk>

**References**:**st: repeated measures***From:*Michael Eisenberg <meisenberg713@gmail.com>

**st: RE: repeated measures***From:*Nick Cox <n.j.cox@durham.ac.uk>

**Re: st: RE: repeated measures***From:*David Bell <dcbell@iupui.edu>

**RE: st: RE: repeated measures***From:*Nick Cox <n.j.cox@durham.ac.uk>

- Prev by Date:
**Re: st: Upcoming NetCourses** - Next by Date:
**Re: st: RE: repeated measures** - Previous by thread:
**RE: st: RE: repeated measures** - Next by thread:
**Re: st: RE: repeated measures** - Index(es):