I have the data that you see on the attachment. They are ranked as: sort firm day
I want to generate a new variable that will rank the variable SM by firm, every 21 days. Then it will go to the next 21 days. So the new variable should take values from 1 to 21.
As a first step I tried the command: egen rank21 = rank(SM), by(firm)
which ranks SM by firm for all days, so that goes from 1 to 7045 in my case.
I probably need something with a forvalues loop. I also need to rank them in descending order, but when I enter rank(-SM) stata doesn't recognize the rank() function.
Thank you in advance,
Dimitrios Chlorokostas
I want to generate a new variable that will rank the variable SM by firm, every 21 days. Then it will go to the next 21 days. So the new variable should take values from 1 to 21.
As a first step I tried the command: egen rank21 = rank(SM), by(firm)
which ranks SM by firm for all days, so that goes from 1 to 7045 in my case.
I probably need something with a forvalues loop. I also need to rank them in descending order, but when I enter rank(-SM) stata doesn't recognize the rank() function.
Thank you in advance,
Dimitrios Chlorokostas
Comment