Hi,
I was wondering if there is a faster way to code cumulative return that the following code:
Is there a Stata command to do that?
Also, I would like to create 1,...,T variables for T years cumulative returns ahead. I have tried the following but the cumulative returns aren't correct. Also, is there a faster way to do that? Thanks!
I was wondering if there is a faster way to code cumulative return that the following code:
Code:
webuse grunfeld, clear xtset company year gen ret = rnormal(0,1)/100 gen ln_ret= ln(1+ret) bys company: gen sum_ln_ret = sum(ln_ret) gen cum_ret = exp(sum_ln_ret)-1
Also, I would like to create 1,...,T variables for T years cumulative returns ahead. I have tried the following but the cumulative returns aren't correct. Also, is there a faster way to do that? Thanks!
Code:
webuse grunfeld, clear xtset company year gen ret = rnormal(0,1)/100 xtset year company forvalues t = 1/5 { gen ret_F`t'=F`t'.ret gen ln_F`t'=ln(1+ret_F`t') order ln_F* egen cum_ln`t' = rowmean(ln_F*) gen cum_r`t'=exp(cum_ln`t')-1 } drop cum_ln* ret_F* ln_F*
Comment