Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
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/