Hello,
I have the following trip data:
I would like to create pairwise combinations in a way that each origin location is placed before a unique destination in order. The data is unique on date, trip_id, vehicle, and stop_number.
Essentially this is how I would like the data to end up looking like:
I tried using the "cross" from Stata but that did not seem like an efficient strategy. Hoping to hear from the pros here.
I have the following trip data:
Code:
* Example generated by -dataex-. For more info, type help dataex clear input str8 date byte trip_id int vehicle str1(stop_number origin) str13 origin_time str1 destination str13 destination_time "1-Jan-24" 1 1000 "1" "A" "1/1/2024 6:00" "B" "1/1/2024 6:03" "1-Jan-24" 1 1000 "2" "B" "1/1/2024 6:05" "C" "1/1/2024 6:09" "1-Jan-24" 1 1000 "3" "C" "1/1/2024 6:12" "D" "1/1/2024 6:15" "1-Jan-24" 1 1000 "4" "D" "1/1/2024 6:17" "E" "1/1/2024 6:26" "1-Jan-24" 1 1000 "5" "E" "1/1/2024 6:28" "F" "1/1/2024 6:32" "1-Jan-24" 2 1001 "1" "A" "1/1/2024 7:00" "B" "1/1/2024 7:03" "1-Jan-24" 2 1001 "2" "B" "1/1/2024 7:05" "C" "1/1/2024 7:09" "1-Jan-24" 2 1001 "3" "C" "1/1/2024 7:12" "D" "1/1/2024 7:15" "1-Jan-24" 2 1001 "4" "D" "1/1/2024 7:17" "E" "1/1/2024 7:26" "1-Jan-24" 2 1001 "5" "E" "1/1/2024 7:28" "F" "1/1/2024 7:32" end
Essentially this is how I would like the data to end up looking like:
Code:
* Example generated by -dataex-. For more info, type help dataex clear input str8 date byte trip_id str1 origin str13 origin_time str1 destination str13 destination_time "1-Jan-24" 1 "A" "1/1/2024 6:00" "B" "1/1/2024 6:03" "1-Jan-24" 1 "A" "1/1/2024 6:00" "C" "1/1/2024 6:09" "1-Jan-24" 1 "A" "1/1/2024 6:00" "D" "1/1/2024 6:15" "1-Jan-24" 1 "A" "1/1/2024 6:00" "E" "1/1/2024 6:26" "1-Jan-24" 1 "A" "1/1/2024 6:00" "F" "1/1/2024 6:32" "1-Jan-24" 1 "B" "1/1/2024 6:05" "C" "1/1/2024 6:09" "1-Jan-24" 1 "B" "1/1/2024 6:05" "D" "1/1/2024 6:15" "1-Jan-24" 1 "B" "1/1/2024 6:05" "E" "1/1/2024 6:26" "1-Jan-24" 1 "B" "1/1/2024 6:05" "F" "1/1/2024 6:32" "1-Jan-24" 1 "C" "1/1/2024 6:12" "D" "1/1/2024 6:15" "1-Jan-24" 1 "C" "1/1/2024 6:12" "E" "1/1/2024 6:26" "1-Jan-24" 1 "C" "1/1/2024 6:12" "F" "1/1/2024 6:32" "1-Jan-24" 1 "D" "1/1/2024 6:17" "E" "1/1/2024 6:26" "1-Jan-24" 1 "D" "1/1/2024 6:17" "F" "1/1/2024 6:32" "1-Jan-24" 1 "E" "1/1/2024 6:28" "F" "1/1/2024 6:32" "1-Jan-24" 2 "A" "1/1/2024 7:00" "B" "1/1/2024 7:03" "1-Jan-24" 2 "A" "1/1/2024 7:00" "C" "1/1/2024 7:09" "1-Jan-24" 2 "A" "1/1/2024 7:00" "D" "1/1/2024 7:15" "1-Jan-24" 2 "A" "1/1/2024 7:00" "E" "1/1/2024 7:26" "1-Jan-24" 2 "A" "1/1/2024 7:00" "F" "1/1/2024 7:32" "1-Jan-24" 2 "B" "1/1/2024 7:05" "C" "1/1/2024 7:09" "1-Jan-24" 2 "B" "1/1/2024 7:05" "D" "1/1/2024 7:15" "1-Jan-24" 2 "B" "1/1/2024 7:05" "E" "1/1/2024 7:26" "1-Jan-24" 2 "B" "1/1/2024 7:05" "F" "1/1/2024 7:32" "1-Jan-24" 2 "C" "1/1/2024 7:12" "D" "1/1/2024 7:15" "1-Jan-24" 2 "C" "1/1/2024 7:12" "E" "1/1/2024 7:26" "1-Jan-24" 2 "C" "1/1/2024 7:12" "F" "1/1/2024 7:32" "1-Jan-24" 2 "D" "1/1/2024 7:17" "E" "1/1/2024 7:26" "1-Jan-24" 2 "D" "1/1/2024 7:17" "F" "1/1/2024 7:32" "1-Jan-24" 2 "E" "1/1/2024 7:28" "F" "1/1/2024 7:32" end
Comment