I am trying to solve the unkown IRR using mm_root function of the moremata package. Here is my example data set
And the code that I am trying use is
I receive the followng error message
<istmt>: 3301 subscript invalid
r(3301);
Code:
clear input float(eps1 eps2 dps1) double prccd float IRR .33 .46 .02 7.66 . .3 .41 .08 6.2 . .38 .49 .13 7.71 . .38 .5 .35 9.9 . 6.8 5.7 3.1 1330 . 1.7 3.2 1 440 . 9.7 11 2.6 999 . 10.6 11.4 2.8 1200 . 1.04 1.18 .21 183 . 1.1 1.23 .22 36.25 . 1.35 1.54 .25 20.5 . 1.05 1.21 .25 10.99 . .9 1.1 .27 19.55 . 1.2 1.36 .33 24.25 . 1.56 1.76 .42 27.8 . .77 .83 .27 10.7 . 1.22 1.4 .43 19.99 . 1.17 1.32 .42 18.165 . .9 1.12 .29 14 . 8.9 9.4 . 1508 . 28.8 30.9 10.2 434 . end
Code:
mata mata clear end generate IRR=. mata z=J(1,1,.) st_view(z,., "IRR prccd eps1 eps2 dps1") function s(x,p,f1,f2,dv) { return(-p+(f2-f1+(dv*x))/x^2) } for (i=1;i<=rows(z);i++) { r=mm_root(IRR=.,&s(),z[i,9]+epsilon(1),1-epsilon(1),1e-9,1000,z[i,2],z[i,3],z[i,4],z[i,5], z[i,6],z[i,7],z[i,8],z[i,9],z[i,10] ) z[i,1]=IRR } end
<istmt>: 3301 subscript invalid
r(3301);
Comment