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]

Re: st: handling dates to find latest date from multiple records


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: handling dates to find latest date from multiple records
Date   Fri, 11 Nov 2011 16:01:46 +0000

I am interpreting the essence of your question to be given by your
subject header.

Many date problems have details ranging from awkward to horrible, but
for other date problems the only detail that matters is that dates are
numbers. So, the latest date is just the maximum date and functions or
-egen- functions to identify maxima appear to be what you need.

For some problems you might need a two-step reduction, e.g.

bysort id: egen max1 =  max(var1)
by id: egen max2 =  max(var2)
by id: egen max3 =  max(var3)

by id : egen max = rowmax(max1 max2 max3)

Nick

On Fri, Nov 11, 2011 at 3:52 PM, Sunday Clark <[email protected]> wrote:

> I am using Stata 12.0. I have a dataset of hospitalized patients with
> hospital stays ranging from 1-30 days. There is a daily data
> collection form that was supposed to be filled out each day of the
> hospitalization for each patient. For most questions on the form,
> there should be a response on each day. Another part of this form asks
> for the date that the doctor thinks the patient is better, the date
> the patient thinks the patient is better, and the date the doctor
> thinks the patient can safely be discharged. This is all supposed to
> be answered on the daily form on the last day of the hospitalization,
> but the individual questions were sometimes answered on the day that
> the individual criterion was met. I would like to be able to identify
> each of these dates and the date on which all three were met, if they
> were met on different dates. Can anyone provide me with suggestions
> for how to do this in an efficient manner? I have the data in long and
> wide format.
>
> In long format it looks like the following:
>
> subjectid       IPF_record      totalIPFs       IPF_ID  IPFQ1   IPFQ2   IPFQ3
> 1       1       1       9       11/07/05        11/08/05        11/07/05
> 2       2       2       58      01/24/06        01/24/06        01/24/06
> 2       1       2       57      .       .       .
> 3       1       1       6       01/07/06        01/08/06        01/08/06
> 4       1       1       10      11/08/05        .       11/08/05
> 5       2       2       12      11/13/05        11/13/05        11/14/05
> 5       1       2       11      11/13/05        11/13/05        11/13/05
> 6       1       1       37      11/27/05        11/27/05        .
> 7       1       1       38      12/04/05        .       12/03/05
> 8       8       8       46      12/10/05        .       12/10/05
> 8       6       8       44      .       .       .
> 8       4       8       42      .       .       .
> 8       7       8       45      12/10/05        .       12/10/05
> 8       3       8       41      .       .       .
> 8       1       8       39      .       .       .
> 8       2       8       40      .       .       .
> 8       5       8       43      .       .       .
>
>

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