Hello,
I have an issue with sorting my data. I have three variables and I want it to be sorted on lopnr and year, and if there are any ties in years it should be sorted so that the value cfar took in the last year ends up highest when it is tied. The first table, at year 2017, illustrates how I want it to look like. If I sort in lopnr year cfar it will just end up like second table and there is my issue. I'm not able to provide you with my dataset due to confidentialty issues.
I thought I could create a new ID variable and then sorting on that but then I get it like in the second table but I would like it how it looks like in the first table.
for the new ID I ran
egen ID=group(lopnr cfar)
Is there any way to force egen group to do what I want? Do you have any other ideas how to solve this?
I have an issue with sorting my data. I have three variables and I want it to be sorted on lopnr and year, and if there are any ties in years it should be sorted so that the value cfar took in the last year ends up highest when it is tied. The first table, at year 2017, illustrates how I want it to look like. If I sort in lopnr year cfar it will just end up like second table and there is my issue. I'm not able to provide you with my dataset due to confidentialty issues.
I thought I could create a new ID variable and then sorting on that but then I get it like in the second table but I would like it how it looks like in the first table.
for the new ID I ran
egen ID=group(lopnr cfar)
Is there any way to force egen group to do what I want? Do you have any other ideas how to solve this?
Cfar | lopnr | year | ID |
275 | 42 | 2014 | 1 |
275 | 42 | 2015 | 1 |
275 | 42 | 2016 | 1 |
275 | 42 | 2017 | 1 |
192 | 42 | 2017 | 2 |
192 | 42 | 2018 | 2 |
Cfar | lopnr | year | ID |
275 | 42 | 2014 | 2 |
275 | 42 | 2015 | 2 |
275 | 42 | 2016 | 2 |
192 | 42 | 2017 | 1 |
275 | 42 | 2017 | 2 |
192 | 42 | 2018 | 1 |
Comment