Generic selectors
Exact matches only
Search in title
Search in content
Search in posts
Search in pages

asrol Cumulative Returns Over 12-months, skipping the Current month

  • 0

asrol Cumulative Returns Over 12-months, skipping the Current month

Category:Uncategorized

Anomaly Hunters has asked: How Can I find cumulative returns from month T-1 to T-12, i.e. not including the current month in the calculation. I want to do it on a rolling window for each firm.

Let us use a small dataset. We shall create this dataset in Stata with the following code

clear
 input byte firm_id str6 date float ret
 1 "200310"         .
 1 "200311"  -.049505
 1 "200312"  .0121528
 1 "200401"  .0360206
 1 "200402" -.0480132
 1 "200403"  .0434783
 1 "200404"  .0933333
 1 "200405"  .0121951
 1 "200406"  .0060241
 1 "200407"  .0883234
 1 "200408" -.0261348
 1 "200409" -.0819209
 1 "200410"      -.02
 1 "200411" -.0062794
 1 "200412"  .0458136
 1 "200501"  .0891239
 1 "200502"  .0443828
 1 "200503"
 end

* Convert the date to Stata format
Code:

tostring date, replace
gen month = mofd(date(date, "YM"))
format month %tm

* Find cumulative returns in a 12-month rolling window
Code:

bys firm_id : asrol ret, stat(product) add(1) window(month 12)

* Lag the returns by one month to skip the current month returns from the calculation
Code:

tsset firm_id month
gen ret_skip1 = L.product12_ret
list month ret product12_ret ret_skip1

*And appreciate the results

Code:

     +---------------------------------------------+
     |   month        ret   product1~t   ret_skip1 |
     |---------------------------------------------|
  1. | 2003m10          .            .           . |
  2. | 2003m11   -.049505     -.049505           . |
  3. | 2003m12    .012153   -.03795382    -.049505 |
  4. |  2004m1    .036021   -.00330034   -.0379538 |
  5. |  2004m2   -.048013   -.05115508   -.0033003 |
     |---------------------------------------------|
  6. |  2004m3    .043478   -.00990092   -.0511551 |
  7. |  2004m4    .093333    .08250829   -.0099009 |
  8. |  2004m5    .012195    .09570959    .0825083 |
  9. |  2004m6    .006024    .10231025    .0957096 |
 10. |  2004m7    .088323    .19967004    .1023103 |
     |---------------------------------------------|
 11. |  2004m8   -.026135     .1683169      .19967 |
 12. |  2004m9   -.081921    .07260733    .1683169 |
 13. | 2004m10       -.02    .05115519    .0726073 |
 14. | 2004m11   -.006279     .0989585    .0511552 |
 15. | 2004m12    .045814    .13550617    .0989585 |
     |---------------------------------------------|
 16. |  2005m1    .089124     .1937088    .1355062 |
 17. |  2005m2    .044383    .30956536    .1937088 |
 18. |  2005m3   -.005312     .2483334    .3095654 |
     +---------------------------------------------+

Leave a Reply