Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Iterative code

    Hello,

    I build an implied cost of capital model and I am looking for an iterartive solution for the capital costs (r_ct) and used the code below.

    I specified the variables ("p0 bps_0 eps_1 eps_2 eps_3 eps_4 eps_5 bps_1 bps_2 bps_3 bps_4 g_lt_rf r_ct") with the given data and set the cost of capital r_ct = 0.10 for the start of the iterative process.

    So when I run the do file I just get a summary of the data for each company and the cost of capital remains 0.10 for every company / period.

    Working with mata is quite new for me. So I am wondering whether I missed something obvious or did something wrong...


    Thanks a lot for your help in advance!


    mata
    mata clear

    end

    mata
    v=J(1,1,.)
    st_view(v,., "p0 bps_0 eps_1 eps_2 eps_3 eps_4 eps_5 bps_1 bps_2 bps_3 bps_4 g_lt_rf r_ct")
    function y(m, v)
    {
    a=v[1]; b=v[2]; c=v[3]; d=v[4]; e=v[5]; f=v[6]; g=v[7]; h=v[8]; i=v[9]; j=v[10]; k=v[11]; l=v[12]
    return((b-a)*((1+m)^5)*(m-l)+(c-m*b)*((1+m)^4)*(m-l)+(d-m*h)*((1+m)^3)*(m-l)+(e-m*i)*((1+m)^2)*(m-l)+(f-m*j)*(1+m)*(m-l)+(g-m*k)*(1+l))
    }

    for (i=1; i<=rows(v); i++) {
    mm_root(m=., &y(),0.00000001,1,0.0001,10000000000,v[i,2],v[i,3],v[i,4],v[i,5],v[i,6],v[i,7],v[i,8],v[i,9],v[i,10],v[i,11],v[i,12],v[i,13])
    v[i,13]=m
    }
    end
    l, noo

Working...
X