Thanks. I think I get it now. Here is a demonstration using rangerun from SSC.
There are lots of details, some simple, some subtle.
Your variable is evidently not invest but data. Or -- if it is something else -- that is your call.
Your time window appears to be -30 0, so the previous 30 days and this day. But you need a proper Stata daily date variable. Your string date variable is no use for this purpose.
There are several definitions of rank and percentile rank. See also https://www.stata.com/support/faqs/s...ing-positions/ for one perspective.
You may not have an analogue of the panel variable company. If not, there is no by() option call.
There are lots of details, some simple, some subtle.
Your variable is evidently not invest but data. Or -- if it is something else -- that is your call.
Your time window appears to be -30 0, so the previous 30 days and this day. But you need a proper Stata daily date variable. Your string date variable is no use for this purpose.
There are several definitions of rank and percentile rank. See also https://www.stata.com/support/faqs/s...ing-positions/ for one perspective.
You may not have an analogue of the panel variable company. If not, there is no by() option call.
Code:
webuse grunfeld, clear capture program drop pcrank program pcrank count if invest < invest[_N] & invest < . scalar i1 = r(N) count if invest == invest[_N] & invest < . scalar i2 = r(N) count if invest < . gen n = r(N) gen rank = i1 + i2 gen pcrank = (i1 + 0.5 * i2) / n end rangerun pcrank, use(invest) int(year -9 0) by(company) list invest n rank pcrank if company == 1 +-------------------------------+ | invest n rank pcrank | |-------------------------------| 1. | 317.6 1 1 .5 | 2. | 391.8 2 2 .75 | 3. | 410.6 3 3 .8333333 | 4. | 257.7 4 1 .125 | 5. | 330.8 5 3 .5 | |-------------------------------| 6. | 461.2 6 6 .9166667 | 7. | 512 7 7 .9285714 | 8. | 448 8 6 .6875 | 9. | 499.6 9 8 .8333333 | 10. | 547.5 10 10 .95 | |-------------------------------| 11. | 561.2 10 10 .95 | 12. | 688.1 10 10 .95 | 13. | 568.9 10 9 .85 | 14. | 529.2 10 6 .55 | 15. | 555.1 10 7 .65 | |-------------------------------| 16. | 642.9 10 9 .85 | 17. | 755.9 10 10 .95 | 18. | 891.2 10 10 .95 | 19. | 1304.4 10 10 .95 | 20. | 1486.7 10 10 .95 | +-------------------------------+
Comment