Dear statalisters,
My data has the following structure
clear
input int(firmid year) byte month double return
1000 1970 2 .00934434
1000 1970 3 .0173867
1000 1970 4 .00503076
1000 1970 5 .00073604
1000 1970 6 .01228391
1000 1970 7 .01249819
1000 1970 8 .00315777
1000 1970 9 -.01552438
1000 1970 10 .00465082
1000 1970 11 .0020976
1000 1970 12 -.00440306
1001 1970 1 -.01761758
1001 1970 2 -.00442809
1001 1970 3 .01371391
1001 1970 4 .01857399
1001 1970 5 -.0107689
1001 1970 6 -.0134988
1001 1970 7 -.01000505
1001 1970 8 .01642262
1001 1970 9 -.00124286
1001 1970 10 .01054097
1001 1970 11 .01086563
1001 1970 12 .00630591
end
My tasks are two-fold:
Could you give some advice on coding this?
Thanks,
Rochelle
My data has the following structure
clear
input int(firmid year) byte month double return
1000 1970 2 .00934434
1000 1970 3 .0173867
1000 1970 4 .00503076
1000 1970 5 .00073604
1000 1970 6 .01228391
1000 1970 7 .01249819
1000 1970 8 .00315777
1000 1970 9 -.01552438
1000 1970 10 .00465082
1000 1970 11 .0020976
1000 1970 12 -.00440306
1001 1970 1 -.01761758
1001 1970 2 -.00442809
1001 1970 3 .01371391
1001 1970 4 .01857399
1001 1970 5 -.0107689
1001 1970 6 -.0134988
1001 1970 7 -.01000505
1001 1970 8 .01642262
1001 1970 9 -.00124286
1001 1970 10 .01054097
1001 1970 11 .01086563
1001 1970 12 .00630591
end
My tasks are two-fold:
- Compute a buy and hold return defined as = (1+ return of month 1) * ((1+ return of month 2)*….*(1+return of month12) -1
- If a year has less than 6 monthly returns, then set the return from 1 above to missing
Could you give some advice on coding this?
Thanks,
Rochelle
Comment