Hi all,
I am trying to calculate hours and minutes for the duration of an operation. The "Date" data is not attached to the time strings so everything is occurring to stata from the baseline date of 01 Jan 1960. As you can see in the attached image, this works fine for data occurring from 12:01 am to 11:59 pm. However, the issue arises when data crosses from say 11:00 pm to 1:00 am (2 hours). Stata thinks this is 31 Dec 1959, and not 02 Jan 1960 (a positive value). I have read through the "Help dates" guide, but I cannot seem to figure out how to alleviate this issue. Here is my code (simplistic, obviously) as well as an attached image of the data.
Thanks in advance for your help.
I am trying to calculate hours and minutes for the duration of an operation. The "Date" data is not attached to the time strings so everything is occurring to stata from the baseline date of 01 Jan 1960. As you can see in the attached image, this works fine for data occurring from 12:01 am to 11:59 pm. However, the issue arises when data crosses from say 11:00 pm to 1:00 am (2 hours). Stata thinks this is 31 Dec 1959, and not 02 Jan 1960 (a positive value). I have read through the "Help dates" guide, but I cannot seem to figure out how to alleviate this issue. Here is my code (simplistic, obviously) as well as an attached image of the data.
Thanks in advance for your help.
Code:
generate double oprepstartds = clock(oper_prep_start, "hm") generate double oparriveds = clock(oper_arrive, "hm") generate double opstartds = clock(oper_start, "hm") generate double opendds = clock(oper_end, "hm") generate double oppostopds = clock(oper_postop, "hm") gen op_duration = opendds - opstartds br participant_id redcap_event_name oper_prep_start oper_arrive oper_start oper_end oper_postop op_duration op_duration_min op_duration_hr gen op_duration_min = op_duration/(60*1000) gen op_duration_hr = op_duration_min/60 format oprepstartds %tc format oparriveds %tc format opstartds %tc format opendds %tc format oppostopds %tc format op_duration %tc
Comment