Hi,
I am working on a dataset almost includes 5000 observation, and I would like to create a new variable based on the sorted-order of another variable.
To put it simply, it is a list of political leaders in each year, thus it is listed as the following:
var1 var2 var3
USA Donald Trump 2017
USA Donald Trump 2018
Since there are some people who left the office and elected again, after sorting the data based on year (var3 in the example), var2 is listed as following:
A - A - A - B - B - A - A - C -C.
Now I have to assign them spell number, and it becomes tricky for person A, who left the office to B and retook it. What I would like to see as result in my new variable is 1 - 1 - 1 - 1 - 1- 2 - 2 - 1 - 1 , as person A serves for second time. If he would stay in the office for 5 years continuously, all would be 1 but we have to assign a new number for the new spell.
In this case, what would you suggest me in assigning spell numbers?
Though I couldn't explain well what I would to do, I hope it will be enough for you.
Thanks,
Cem
I am working on a dataset almost includes 5000 observation, and I would like to create a new variable based on the sorted-order of another variable.
To put it simply, it is a list of political leaders in each year, thus it is listed as the following:
var1 var2 var3
USA Donald Trump 2017
USA Donald Trump 2018
Since there are some people who left the office and elected again, after sorting the data based on year (var3 in the example), var2 is listed as following:
A - A - A - B - B - A - A - C -C.
Now I have to assign them spell number, and it becomes tricky for person A, who left the office to B and retook it. What I would like to see as result in my new variable is 1 - 1 - 1 - 1 - 1- 2 - 2 - 1 - 1 , as person A serves for second time. If he would stay in the office for 5 years continuously, all would be 1 but we have to assign a new number for the new spell.
In this case, what would you suggest me in assigning spell numbers?
Though I couldn't explain well what I would to do, I hope it will be enough for you.
Thanks,
Cem
Comment