Hey all

I am having some trouble with transforming some of the time stamps in my data, they are currently formatted like this 21:40:56 and

The variable appt_length (appointment length in seconds) (type= float format= %9.0g) was calculated in R using the variables consultant_started and consultant_ended (both are type =float, format= %tcHH:MM:SS)in my dataset

however in some cases consultant_ended is missing. So i want to calculate and replace the missing values of appt_length (in seconds) using consultant_completed minus consultant_started

code:
gen appt_length_new = appt_length

count if !missing(consultant_started) & missing(consultant_ended)

replace appt_length_new = consultant_completed - consultant_started if missing(appt_length_new)

^ this doesn't work and transforms the times in a strange format (last line)

however as you saw the appt_length variable was calculated using another software, so it isn't formatted as seconds in STATA.

How can i
1. Format the original appt_length variable in seconds correctly for stata (everything ive read mentions transformation from a string not from a float)
2. Use the two new variables consultant_completed MINUS consultant_started to calculate and replace the missing values for appt_length in SECONDS
3. Then create a new variable to transform appt_length into minutes.

i hope thats all clear, my dissertation deadline is approaching and im struggling with the stata code - thank you in advance!


code i used to transform the times

gen consultant_started1 = clock(consultant_started,"hms")
format consultant_started1 %tcHH:MM:SS