Hi,
I have the following dataset that will be extended to ret_F4, ...... , ret_F`n':
I would like to calculate in one loop the "n" cumulative returns starting from ret_F`n' and at each iteration remove the last period: (1/K); (1/K-1) ... (1/1). Here is the code I have so far, that need to be fixed:
Thanks in advance!
I have the following dataset that will be extended to ret_F4, ...... , ret_F`n':
HTML Code:
permno date ret_F1 ret_F2 ret_F3 10000 1986m7 -.9555115 -.0588405 -.2776318 10000 1986m8 -.0588405 -.2776318 .0582689 10000 1986m9 -.2776318 .0582689 -.4737844 10000 1986m10 .0582689 -.4737844 10000 1986m11 -.4737844 10000 1986m12 10001 1986m1 .0202027 .0248877 .0098523 10001 1986m2 .0248877 .0098523 -.0098523 10001 1986m3 .0098523 -.0098523 -.0131555 10001 1986m4 -.0098523 -.0131555 -.0102565 10001 1986m5 -.0131555 -.0102565 .0696799 10001 1986m6 -.0102565 .0696799 -.0030817 10001 1986m7 .0696799 -.0030817 .0384663 10001 1986m8 -.0030817 .0384663 .0550598
Code:
local K 3 tsegen cum_ret03 = rowtotal(ret_F(1/`K'), `K') gen cum_ret3 = exp(cum_ret03)-1 tsegen cum_ret02 = rowtotal(ret_F(1/`K'-1), `K') gen cum_ret2 = exp(cum_ret02)-1 tsegen cum_ret01 = rowtotal(ret_F(1/`K'-2), `K') gen cum_ret1 = exp(cum_ret01)-1
Comment