Dear all,

I would like to construct 12-month rolling returns, however, I have weekly panel data.
I'm having difficulty to construct this variable as it needs to be in months and on a rolling basis while my data is in weeks. The 12-month returns can either be the sum or the cumulative return of the previous 12 months. Any help or suggestions on how I can construct this variable would be very much appreciated.

Below I provide a sample of the data.

(Stata version I'm using: 16.1)

Kind regards,
Rudolf

Code:
* Example generated by -dataex-. For more info, type help dataex
clear
input float(id week month) double returns
1 3042 702    .012764235794349599
1 3043 702     .02041700010886416
1 3044 702    .005766705609858036
1 3045 702  -.0010118762203354947
1 3046 702   .0037670689960860315
1 3047 703   .0020717289007734507
1 3048 703  -.0027301527152303606
1 3049 703    .012967288581421599
1 3050 703    .016810451552950134
1 3051 704   -.017451212560778195
1 3052 704     .01321841905069504
1 3053 704    .002523396600736305
1 3054 704    .003559061686973841
1 3055 705   -.022511215647682548
1 3056 705   -.038632962712038754
1 3057 705   -.011971201049163938
1 3058 705   -.034610824362276985
1 3059 705    .019461714662611485
1 3060 706     .01673169482139336
1 3061 706    -.02534775624037966
1 3062 706    -.04442830016731991
1 3063 706     .06272190829622559
1 3064 707   -.048711595067593594
1 3065 707   -.009606348932314823
1 3066 707    -.08471454284153879
1 3067 707      .0539041066461774
1 3068 708     .02832558045936856
1 3069 708    .020540449422192353
1 3070 708    .034897736377320854
1 3071 708   -.008661802334245294
1 3072 708     .04053567091016319
1 3073 709   -.006206407207968889
1 3074 709    .026716585517123193
1 3075 709    .007725641131401062
1 3076 709  -.0014473493537763282
1 3077 710   -.007511112279538601
1 3078 710    .020684414252173156
1 3079 710   -.008034596343820866
1 3080 710     .02202723012305796
1 3081 711    .008937508273809902
1 3082 711    .005946493537209996
1 3083 711    .006635991564863275
1 3084 711    .019613407901488245
1 3085 711   -.007053279550746083
1 3086 712    -.05344061367213726
1 3087 712     .01240828912705183
1 3088 712   -.005865209412393109
1 3089 712     -.0375175136141479
1 3090 713     .06374666118063033
1 3091 713 .000026310153771191835
1 3092 713    .022063414216972888
1 3093 713     .01237669587135315
1 3094 714  .00003841141872884535
1 3095 714    .019829148508186734
1 3096 714   -.011195861606217328
1 3097 714    .004324792418628931
1 3098 714    -.06548765726620331
1 3099 715    .013873234513048338
1 3100 715    .018475859658792615
1 3101 715   -.014217216521501541
1 3102 715    .014838154644388535
1 3103 716     .01329785556299612
1 3104 716    .005806573200970888
1 3105 716   -.004276997467968613
1 3106 716   -.012829712126404047
1 3107 717   -.009080902906134725
1 3108 717    .009824079577811062
1 3109 717    .011757313273847103
1 3110 717    .027176437433809042
1 3111 717    .010644883563487362
1 3112 718  .00003227881515766029
1 3113 718     .01688830151537779
1 3114 718    .019417997032030065
1 3115 718   -.007976460221756174
1 3116 719    .005581855117895884
1 3117 719    .018926126552314848
1 3118 719    .010717585508579486
1 3119 719    .004122246805560392
1 3120 720    .013227885514027982
1 3121 720     .02085257862021256
1 3122 720    .015365185190610309
1 3123 720    -.00986608909345943
1 3124 720     .01796149427212157
1 3125 721    .019984229487153837
1 3126 721    .009825398348017433
1 3127 721    -.07975544896908104
1 3128 721    -.02987141087390821
1 3129 722    -.03535800892859697
1 3130 722     -.1481177918612957
1 3131 722    .006236542481929064
1 3132 722    .049138973001390696
1 3133 723     .02604389563202858
1 3134 723     .07715939012885276
1 3135 723   -.034511258359998465
1 3136 723     .03960016408969169
1 3137 723    .032396498461213064
1 3138 724    .017279934928711604
1 3139 724    .025013391750277947
1 3140 724    .016323459248746452
1 3141 724    .026496227842703002
end
format %tw week
format %tm month