Hi!
I have a problem I would appreciate your help with. My data (>700 000 rows) consists of the variables id, id2 and var and I want to generate newvar (se below).
Newvar should be based on the number of distinct id2 per id, starting with 1 and counting upwards - order defined by the quantity of var.
data
If I use _n it counts each row per id2. I want newvar to be the same for each id2.
Thank you so much!
I have a problem I would appreciate your help with. My data (>700 000 rows) consists of the variables id, id2 and var and I want to generate newvar (se below).
Newvar should be based on the number of distinct id2 per id, starting with 1 and counting upwards - order defined by the quantity of var.
data
id | id2 | var | newvar |
1 | 1 | 1000 | 1 |
1 | 2 | 2000 | 2 |
2 | 3 | 1200 | 1 |
2 | 3 | 8000 | 1 |
If I use _n it counts each row per id2. I want newvar to be the same for each id2.
Thank you so much!
Comment