Quantcast
Channel: Statalist
Viewing all articles
Browse latest Browse all 65124

Cost of equity: st-view do not generate results

$
0
0
Hi everyone,

I'm running code using Mata, however, I don't understand why Mata do not generate the results for all of my observations.

In fact, as you can see in the data I provide below, the gls variable has only one observation whereas it should have 5 in total. I tried to do manually by Excel for year==2008, and I have the result (gls)

many thanks for your help!


Here is my code and a sub-sample:

Code:
    cap drop gls
    gen gls=.
    
    mata
    mata clear
    z=(1,1,.)
    
    st_view(z,.,"gls price_ibes_w bveps_comp_w feps1_pos_w feps2_pos_w ltg_pos roe_ind_mov dpo_comp") 
    function w(x,p,b0,f1_,f2_,g,ii,dv) {
        disc = (1+x)^(-10/12) //discount factor from month+10 to present
        k = 1 - dv
        
        f1=f1_ *disc
        f2=f2_ *disc
        f3=f2*(1+g)  
        tf3 = f1+f2+f3
        
        b1=b0+f1*k
        b2=b0+(f1+f2)*k
        b3=b0+tf3*k
        
        fr3 = f3/b2
        con = (fr3-ii)/9
                
        fr4=fr3-con
        
        fr5=fr4-con
        fr6=fr4-2*con
        fr7=fr4-3*con
        fr8=fr4-4*con
        fr9=fr4-5*con
        fr10=fr4-6*con
        fr11=fr4-7*con
        fr12=fr4-8*con
            
        f4=fr4*b3
        tf4=tf3+f4
        b4=b0+tf4*k
        
        f5=fr5*b4
        tf5=tf4+f5
        b5=b0+tf5*k
        
        f6=fr6*b5
        tf6=tf5+f6
        b6=b0+tf6*k
        
        f7=fr7*b6
        tf7=tf6+f7
        b7=b0+tf7*k
        
        f8=fr8*b7
        tf8=tf7+f8
        b8=b0+tf8*k
        
        f9=fr9*b8
        tf9=tf8+f9
        b9=b0+tf9*k
            
        f10=fr10*b9
        tf10=tf9+f10
        b10=b0+tf10*k
        
        f11=fr11*b10
        tf11=tf10+f11
        b11=b0+tf11*k
        
        f12=fr12*b11
            
        t1 = (f1-x*b0)/(1+x)
        t2 = (f2-x*b1)/(1+x)^2
        t3 = (f3-x*b2)/(1+x)^3
        t4 = (f4-x*b3)/(1+x)^4
        t5 = (f5-x*b4)/(1+x)^5
        t6 = (f6-x*b5)/(1+x)^6
        t7 = (f7-x*b6)/(1+x)^7
        t8 = (f8-x*b7)/(1+x)^8
        t9 = (f9-x*b8)/(1+x)^9
        t10 = (f10-x*b9)/(1+x)^10
        t11= (f11-x*b10)/(1+x)^11
        t12= (f12-x*b11)/(1+x)^12
        tv= t12/x
            
        return(-p+b0+t1+t2+t3+t4+t5+t6+t7+t8+t9+t10+t11+tv)
    }
    
    for (i=1;i<=rows(z);i++) {
        r=mm_root(gls=.,&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,1]= gls
        }
        
    end
    
    drop if missing(t)
    sum gls
Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input double year float(roe_ind_mov dpo_comp ltg_pos id feps1_pos_w feps2_pos_w) double price_ibes_w float(bveps_comp_w gls)
2006 .13732198  .01957673   . 3 .47 .53 15.84  7.386957         .
2007 .13418032   .0301397 .12 3 .31 .36   9.7  7.713243         .
2008 .12149094 .015837386 .12 3 .33 .36   9.8 11.033774         .
2009 .10040423 .018786145 .12 3   . .18   7.8 10.937116         .
2010  .0818014 .018717727 .12 3 .34 .39 10.73 10.956161 .06888516
end

Viewing all articles
Browse latest Browse all 65124

Trending Articles