Hi everyone,
I need to calculate a time difference, between two variables: start_time and end_time[_n-1].
But with a special condition:
dataex:
-interlude-'s creation
Thank you in advance.
Best,
--
Michael
I need to calculate a time difference, between two variables: start_time and end_time[_n-1].
But with a special condition:
- If end_time[_n-1] for individual i begins before 9 p.m. and start_time continues after 9p.m. up to 9a.m, I should create a new variable that takes into account the total amount of time elapsed since -end_time[_n-1] (trip 1) and start_time (trip 2), and then substract from this amount the time in which parking spots are free (to give a little context, parking is free from 9 p.m. until 9 a.m.). I have already a variable (interlude) that is the time elapsed since end_time[_n-1] and start_time. But I need to create a new variable that substracts the time between the free scheme range (the fraction of time between 9 p.m. and 9 a.m.,) from the -interlude- variable. Could you give me some insights, please?
dataex:
Code:
* Example generated by -dataex-. For more info, type help dataex clear input str9 individ_ID double(start_time end_time) float interlude "1000154_1" 59400000 60300000 . "1000154_1" 79200000 81000000 315 "1000154_2" 64800000 66600000 . "1000154_2" 79200000 81000000 210 "1000289_1" 28800000 30600000 . "1000289_1" 36000000 37800000 90 "1000289_3" 35400000 36000000 . "1000289_3" 52200000 54000000 270 "1000289_3" 61200000 62400000 120 "1000289_3" 75600000 76800000 220 end format %tC start_time format %tC end_time
Code:
by individ_ID (start_time), sort: gen interlude = /// clockdiff(end_time[_n-1], start_time, "m") if _n > 1 & (end_time[_n-1] < start_time | date[_n-1] < date)
Best,
--
Michael
Comment