Bookmark and Share

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]

st: AW: Merging 2 variables to calculate time elapse (time/date)


From   <Stefan.Gawrich@hlpug.hessen.de>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: AW: Merging 2 variables to calculate time elapse (time/date)
Date   Thu, 15 Apr 2010 15:01:54 +0200

Var2date: Date patient arrived at the hospital, example: 13 Nov 09
Var2time: Time patient arrived at the hospital, example: 02:32


In this case the patient departed before he/she arrived. 
But I suppose that's just a typo. 



Try this formula:
This is just a simple calculation without any date or time functions

gen hosptime = (Var2date - Var1date) * 24 * 60 + ///
(real(substr(Var2time,1,2)) - real(substr(Var1time,1,2))) * 60 ///
+ real(substr(Var2time,4,2)) - real(substr(Var1time,4,2))


1. line: Date difference calculated in minutes
2. line: added: difference in whole hours from time variables converted to minutes
3. line: added: difference in minutes from time variable 

In the long run working with date and time functions is favourable.

Stefan


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