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]

st: RE: calculating elapsed time


From   Nick Cox <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   st: RE: calculating elapsed time
Date   Wed, 24 Nov 2010 10:35:14 +0000

You need to convert the strings to numbers and do the arithmetic. It's as basic as that. 

Assuming that your -date1- and -date2- are Stata daily dates

gen elapsed_time = 
24 * (date2 - date1) 
+ real(HH2) - real(HH1) 
+ (real(MM2) - real(MM1)) / 60 

That's one command, just spaced for legibility. 

Stata 11 offers full support for date-times. 

Nick 
[email protected] 

Mendoza Aldana, Dr Jorge Antonio 

I am using Stata 10 and I would like to calculate the elapsed time, in hours, between two time points. My data is formatted as below, the hours and minutes are separate string variables.
variable: date1  HH1  MM1  date2  HH2  MM2
          -----  ---  ---  -----  ---  ---
format:   date   str  str  date   str  str

I would appreciate very much your assistance in finding a way to solve this or indicating me any related link.

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