Hey Stata Community!
I have a question concerning generating a new variable.
My dataset looks like this:
What I would like to do is generate a new variable, that tells me the date rank order per product, like this:
I already tried "egen" and "rank" as commands, but I never got the numbers I wanted in the rank variable.
I think the problem is that I want to create a rank that is based on 2 prior variables (product AND date). (btw: I have my date variable as numeric and as well as string, if I need to take the other one. So far I worked with the numeric one.)
I would be very happy if someone could help!
I have a question concerning generating a new variable.
My dataset looks like this:
| Product | Date |
| A | 05/2017 |
| A | 05/2017 |
| A | 08/2017 |
| A | 08/2017 |
| A | 12/2018 |
| A | 03/2019 |
| B | 01/2014 |
| B | 02/2014 |
| C | 03/2012 |
| C | 03/2012 |
| C | 03/2012 |
| C | 08/2012 |
| D | 01/2017 |
| D | 05/2017 |
| Product | Date | Rank |
| A | 05/2017 | 1 |
| A | 05/2017 | 1 |
| A | 08/2017 | 2 |
| A | 08/2017 | 2 |
| A | 12/2018 | 3 |
| A | 03/2019 | 4 |
| B | 01/2014 | 1 |
| B | 02/2014 | 2 |
| C | 03/2012 | 1 |
| C | 03/2012 | 1 |
| C | 03/2012 | 1 |
| C | 08/2012 | 2 |
| D | 01/2017 | 1 |
| D | 05/2017 | 2 |
I already tried "egen" and "rank" as commands, but I never got the numbers I wanted in the rank variable.
I think the problem is that I want to create a rank that is based on 2 prior variables (product AND date). (btw: I have my date variable as numeric and as well as string, if I need to take the other one. So far I worked with the numeric one.)
I would be very happy if someone could help!

Comment