Hello,
I run the following forvalues loop:
And this is what my data looks like after running the code:
The code just stops at line 11 and does not run through (the values for the variable "crspret" are just (1+vwretd) which means that they did not change however they should have changed if the loop would be applied). I cannot explain why this is the case. Maybe someone has an idea what the issue is.
I run the following forvalues loop:
Code:
local count=_N local j = 1 local u = 1 local i = 2 gen crspret= 1+vwretd set trace on forvalues j = `u'/`count'{ if (speriod[`u']==bdate[`i']) & (cusip[`u']==cusip[`i']) { replace crspret = crspret[`u']*(1+vwretd[`i']) in `u' local u = `u'+1 local i = `u'+1 } else if speriod[`u']!=bdate[`i'] & (cusip[`u']==cusip[`i']) { replace crspret = (crspret[`u'])*(1+vwretd[`i']) in `u' local i = `i'+1 } else if cusip[`u']!=cusip[`i'] { replace crspret =. in `u' local u = `u'+1 local i = `u'+1 } }
Code:
* Example generated by -dataex-. For more info, type help dataex clear input float(cusip bdate speriod vwretd crspret) 1 1 5 .01 1.0192497 1 2 6 .1 1.0293413 1 3 7 -.06 .9264072 1 4 8 -.025 1.0249612 1 5 9 .001 1.166879 1 6 10 .02 1.1610502 1 7 11 -.01 1.1212103 1 8 12 .04 1.200488 1 9 13 .11 1.1427721 1 10 14 -.004 1.0346719 1 11 15 -.015 1.0336591 1 12 16 .06 1.06 1 13 17 -.01 .99 1 14 18 .005 1.005 2 1 5 .01 1.01 2 2 6 .1 1.1 2 3 7 -.06 .94 2 4 8 -.025 .975 2 5 9 .001 1.001 2 6 10 .02 1.02 2 7 11 -.01 .99 2 8 12 .04 1.04 2 9 13 .11 1.11 2 10 14 -.004 .996 2 11 15 -.015 .985 2 12 16 .06 1.06 2 13 17 -.01 .99 2 14 18 .005 1.005 3 1 5 .01 1.01 3 2 6 .1 1.1 3 3 7 -.06 .94 3 4 8 -.025 .975 3 5 9 .001 1.001 3 6 10 .02 1.02 3 7 11 -.01 .99 3 8 12 .04 1.04 3 9 13 .11 1.11 3 10 14 -.004 .996 3 11 15 -.015 .985 3 12 16 .06 1.06 3 13 17 -.01 .99 3 14 18 .005 1.005 end
Comment