Hello,
I'm using Stata 14.2, and I'm trying to figure out how to rank a set of numbers using sequential integers, rather than leaving gaps in the case of ties. For example, I have data in the format of the first column, and I would like to generate a new variable shown in the second column:
As far as I know, the egen command doesn't have this option; the track option for rank produces the same ranking in the first column. I can accomplish my goal with an array in R by finding the position in an array of unique values (explained further in the comments here) but I'd like to get it done in Stata if possible. Does anyone have any ideas? Thanks in advance!
I'm using Stata 14.2, and I'm trying to figure out how to rank a set of numbers using sequential integers, rather than leaving gaps in the case of ties. For example, I have data in the format of the first column, and I would like to generate a new variable shown in the second column:
Current_rank | New_rank_no_gaps |
1 | 1 |
2 | 2 |
3 | 3 |
3 | 3 |
5 | 4 |
6 | 5 |
6 | 5 |
8 | 6 |
9 | 7 |
10 | 8 |
As far as I know, the egen command doesn't have this option; the track option for rank produces the same ranking in the first column. I can accomplish my goal with an array in R by finding the position in an array of unique values (explained further in the comments here) but I'd like to get it done in Stata if possible. Does anyone have any ideas? Thanks in advance!
Comment