Hi all,
I’m working with a dataset of individual actions where each row represents a single action with:
close_time of previous actions < open_time of the current action. Note that some actions are overlapping, so I cannot just sort by open_time.
Ideally, I’d like to do this efficiently with rangestat that can handle millions of actions.
Below is a small example dataset (15 observations) you can copy and paste to experiment with. Any guidance on how to implement this condition efficiently would be greatly appreciated!
Thank you, Costas
clear
input int clientid byte UP str19 open_time_str str19 close_time_str float outcome_pct
1 0 "01feb2016 09:00:00" "01feb2016 15:00:00" -5.0
1 1 "01feb2016 13:00:00" "01feb2016 20:00:00" -4.2
1 0 "01feb2016 17:00:00" "02feb2016 01:00:00" -3.4
1 1 "01feb2016 21:00:00" "02feb2016 06:00:00" -2.6
1 0 "02feb2016 01:00:00" "02feb2016 11:00:00" -1.8
2 0 "02feb2016 09:00:00" "02feb2016 15:00:00" -1.0
2 1 "02feb2016 13:00:00" "02feb2016 20:00:00" -0.2
2 0 "02feb2016 17:00:00" "03feb2016 01:00:00" 0.6
2 1 "02feb2016 21:00:00" "03feb2016 06:00:00" 1.4
2 0 "03feb2016 01:00:00" "03feb2016 11:00:00" 2.2
3 0 "03feb2016 09:00:00" "03feb2016 15:00:00" 3.0
3 1 "03feb2016 13:00:00" "03feb2016 20:00:00" 3.8
3 0 "03feb2016 17:00:00" "04feb2016 01:00:00" 4.6
3 1 "03feb2016 21:00:00" "04feb2016 06:00:00" 5.4
3 0 "04feb2016 01:00:00" "04feb2016 11:00:00" 6.2
end
* Convert to true %tc datetimes
gen double open_time = clock(open_time_str, "DMYhms")
gen double close_time = clock(close_time_str, "DMYhms")
format open_time close_time %tcDDmonCCYY_HH:MM:SS
drop open_time_str close_time_str
label var UP "Action type (0 or 1)"
list, sepby(clientid)
I’m working with a dataset of individual actions where each row represents a single action with:
- clientid: person ID
- UP: type of action (1 or 0 )
- open_time and close_time: datetimes when the action started and ended
- outcome_pct: outcome of the action
close_time of previous actions < open_time of the current action. Note that some actions are overlapping, so I cannot just sort by open_time.
Ideally, I’d like to do this efficiently with rangestat that can handle millions of actions.
Below is a small example dataset (15 observations) you can copy and paste to experiment with. Any guidance on how to implement this condition efficiently would be greatly appreciated!
Thank you, Costas
clear
input int clientid byte UP str19 open_time_str str19 close_time_str float outcome_pct
1 0 "01feb2016 09:00:00" "01feb2016 15:00:00" -5.0
1 1 "01feb2016 13:00:00" "01feb2016 20:00:00" -4.2
1 0 "01feb2016 17:00:00" "02feb2016 01:00:00" -3.4
1 1 "01feb2016 21:00:00" "02feb2016 06:00:00" -2.6
1 0 "02feb2016 01:00:00" "02feb2016 11:00:00" -1.8
2 0 "02feb2016 09:00:00" "02feb2016 15:00:00" -1.0
2 1 "02feb2016 13:00:00" "02feb2016 20:00:00" -0.2
2 0 "02feb2016 17:00:00" "03feb2016 01:00:00" 0.6
2 1 "02feb2016 21:00:00" "03feb2016 06:00:00" 1.4
2 0 "03feb2016 01:00:00" "03feb2016 11:00:00" 2.2
3 0 "03feb2016 09:00:00" "03feb2016 15:00:00" 3.0
3 1 "03feb2016 13:00:00" "03feb2016 20:00:00" 3.8
3 0 "03feb2016 17:00:00" "04feb2016 01:00:00" 4.6
3 1 "03feb2016 21:00:00" "04feb2016 06:00:00" 5.4
3 0 "04feb2016 01:00:00" "04feb2016 11:00:00" 6.2
end
* Convert to true %tc datetimes
gen double open_time = clock(open_time_str, "DMYhms")
gen double close_time = clock(close_time_str, "DMYhms")
format open_time close_time %tcDDmonCCYY_HH:MM:SS
drop open_time_str close_time_str
label var UP "Action type (0 or 1)"
list, sepby(clientid)

Comment