Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: RE: summarizing dates


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: RE: summarizing dates
Date   Sun, 19 Aug 2007 17:42:27 +0100

Jeph Herrin asked 
 
> I'm working with multiple observations per subject,
> each with multiple date fields (eg, admission to hospital,
> discharge from hospital, readmission, death). In trying
> to work with them, I would like to be able to summarize
> them. Eg,
> 
> . sum admit_date if missing(disch_date)
> 
> But of course, this produces Stata elapsed date values,
> which are only barely meaningful without formatting.
> What I'd like to do is something like the above but get
> mean, median etc displayed as formatted dates. Is there
> a utility out there that can help? I know I can convert
> them all to Julian dates, but those will be barely more
> intelligible, and YYYYMMDD format will give distorted
> summary values.

Svend Juul suggested 

> I assume that your dates are standard Stata dates. Try this:
 
> . tabstat admit_date if missing(disch_date) , stat(mean median) format(%d)

Thomas J. Steichen suggested 
 
> Try the format option of summarise:
> 
>   . sum admit_date if missing(disch_date), format

Three further comments: 

1. The -tabstat- solution is good, except that any -format- 
you specify applies to _all_ results, including statistics 
that are definitely not elapsed dates (n, cv, skewness, kurtosis, ...) 
and statistics that are measured in the same units as dates 
but are not themselves dates (sd, range, ...). More generally, I 
wish -tabstat- would accept a vector of formats, as will 
some user-written commands. 

2. The -summarize- solution is also good. Interestingly, 
-summarize- with format %d does what I regard as the 
right thing with standard deviation, even though it has
the same units as the variable. Let's regard that as 
a feature. 

3. There is a dedicated utility out there, -summdate- from SSC. 
it is more indicative than definitive. 

Nick 
n.j.cox@durham.ac.uk 

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