Hey all,

I am trying to replica a momentum trading strategy for which I'm building portfolios based on the 12 - 1 cumulative returns. This means that for each observation I calculate the cumulative return of the 12 months before, but without the 1 month before. My dataset is ordered like this:

firm_id date company stockprice market_value ret
1 200310 77 BANK (#T) - 77 BANK (#T) 3030 232266.8
1 200311 77 BANK (#T) - 77 BANK (#T) 2880 220768.4 -.049505
1 200312 77 BANK (#T) - 77 BANK (#T) 2915 223451.4 .0121528
1 200401 77 BANK (#T) - 77 BANK (#T) 3020 231500.2 .0360206
1 200402 77 BANK (#T) - 77 BANK (#T) 2875 220385.1 -.0480132
1 200403 77 BANK (#T) - 77 BANK (#T) 3000 229967.1 .0434783
1 200404 77 BANK (#T) - 77 BANK (#T) 3280 251430.7 .0933333
1 200405 77 BANK (#T) - 77 BANK (#T) 3320 254496.9 .0121951
1 200406 77 BANK (#T) - 77 BANK (#T) 3340 256030.1 .0060241
1 200407 77 BANK (#T) - 77 BANK (#T) 3635 278643.5 .0883234
1 200408 77 BANK (#T) - 77 BANK (#T) 3540 271361.2 -.0261348
1 200409 77 BANK (#T) - 77 BANK (#T) 3250 249131 -.0819209
1 200410 77 BANK (#T) - 77 BANK (#T) 3185 244148.4 -.02
1 200411 77 BANK (#T) - 77 BANK (#T) 3165 242615.3 -.0062794
1 200412 77 BANK (#T) - 77 BANK (#T) 3310 253730.4 .0458136
1 200501 77 BANK (#T) - 77 BANK (#T) 3605 276343.8 .0891239
1 200502 77 BANK (#T) - 77 BANK (#T) 3765 288608.7 .0443828
1 200503 77 BANK (#T) - 77 BANK (#T) 3745 287075.6 -.0053121
What would be the best way going forward to calculate the 12-1 cumulative returns for each observation (starting at 200411) ? I know it has something to do with the rangestat command but I can't seem to make it work the way I want it to.

Thanks in advance.