Hello,
I'm trying to rank companies by their profits. This is the kind of result I'm trying to create:
I've tried:
But of course this doesn't work because the by(company) option means that each company is its own 1st rank. If skip the "by(company)" option, then the 2nd rank isn't 2, but whatever row number the next rank occurs (so for example in a large dataset, something like 1020). If I use "unique" rather than "track," then the rank just corresponds to the row number, and "field" doesn't work either.
How do I get the correct ranks so that they are both tied (i.e. multiple companies can rank in 1st position) and grouped by company?
Related posts:
- https://www.statalist.org/forums/for...he-rank-option
- https://www.stata.com/statalist/arch.../msg00581.html
Thank you!
I'm trying to rank companies by their profits. This is the kind of result I'm trying to create:
company | year | avg_profit | rank |
honda | 1970 | 10 | 1 |
honda | 1971 | 10 | 1 |
toyota | 1970 | 10 | 1 |
toyota | 1971 | 10 | 1 |
ford | 1970 | 11 | 2 |
ford | 1972 | 11 | 2 |
Code:
sort avg_profit company egen rank = rank(avg_profit), by(company) track
How do I get the correct ranks so that they are both tied (i.e. multiple companies can rank in 1st position) and grouped by company?
Related posts:
- https://www.statalist.org/forums/for...he-rank-option
- https://www.stata.com/statalist/arch.../msg00581.html
Thank you!
Comment