Dear all,

In the course of my Master's thesis I intend to calculate an implied cost of capital (ICC) from a 16-period earnings forecast. With the help of Statalist I was able to reproduce the code below that functions when limiting the forecasting horizon to 6 periods. Yet, when running the code with the full horizon (as presented), I encounter the problem that the number of additional arguments for mm_root is restricted to 10. I went through several older posts dealing with a similar problem, but cannot manage to apply the proposed solutions to my dataset.

Comments or instructions on how to solve this issue and retrieve r would be of great help. Any other feedback to improve the code is also highly appreciated.
Thanks in advance!

https://www.statalist.org/forums/for...equity-capital
https://www.stata.com/statalist/arch.../msg00023.html

Code:
generate icc=.
mata
mata clear
z=J(1,1,.)
st_view(z,., "icc GDP_g_lag1 P b1 FE1 FE2 FE3 FE4 FE5 FE6 FE7 FE8 FE9 FE10 FE11 FE12 FE13 FE14 FE15 FE16")
function w(r,g,p,b1,f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13,f14,f15,f16)
{
    t1 = f1*(1-b1)/(1+r)
    t2 = f2*(1-(b1-(b1-g/r)/15))/(1+r)^2
    t3 = f3*(1-(b1-2/15*(b1-g/r)))/(1+r)^3
    t4 = f4*(1-(b1-3/15*(b1-g/r)))/(1+r)^4
    t5 = f5*(1-(b1-4/15*(b1-g/r)))/(1+r)^5
    t6 = f6*(1-(b1-5/15*(b1-g/r)))/(1+r)^6
    t7 = f7*(1-(b1-6/15*(b1-g/r)))/(1+r)^7
    t8 = f8*(1-(b1-7/15*(b1-g/r)))/(1+r)^8
    t9 = f9*(1-(b1-8/15*(b1-g/r)))/(1+r)^9
    t10 = f10*(1-(b1-9/15*(b1-g/r)))/(1+r)^10
    t11 = f11*(1-(b1-10/15*(b1-g/r)))/(1+r)^11
    t12 = f12*(1-(b1-11/15*(b1-g/r)))/(1+r)^12
    t13 = f13*(1-(b1-12/15*(b1-g/r)))/(1+r)^13
    t14 = f14*(1-(b1-13/15*(b1-g/r)))/(1+r)^14
    t15 = f15*(1-(b1-14/15*(b1-g/r)))/(1+r)^15
    tv = f16/(r*(1+r)^15)
    return(-p+t1+t2+t3+t4+t5+t6+t7+t8+t9+t10+t11+t12+t13+t14+t15+tv)
}
for (i=1;i<=rows(z);i++) {
    x=mm_root(icc=.,&w(),smallestdouble(),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,11],z[i,12],z[i,13],z[i,14],z[i,15],z[i,16],z[i,17],z[i,18],z[i,19],z[i,20])
    z[i,1]=icc
}
end