I have a dataset with the start and end date of different events. A major event may constitute of different events happening in sequence (if the end date of an event = start date of another event, then they belong to the same major event). I am trying to create a code that identifies major events.
I have created a toy example of a dataset with two variables (var1, var2), where var1 refers to the start date and var2 to the end date in my real data.
I would like to give each row an id which grows in ascending order of var1 and, most importantly, is kept constant if the value of var1 coincides with var2 of *any other row*.
The output I would be looking for is the following:
Many thanks!
I have created a toy example of a dataset with two variables (var1, var2), where var1 refers to the start date and var2 to the end date in my real data.
Code:
input var1 var2 1 10 5 9 6 11 10 15 16 17 end list
The output I would be looking for is the following:
Code:
input var1 var2 new_var 1 10 1 10 15 1 5 9 2 6 11 3 16 17 4 end list
Comment