/* =========================== include file ====================================================== */ vn_z = getname(path_dat $+n_dat); @loads variable names @ call dstat(path_dat $+n_dat, 0); print;" ==========================================================================="; print " ================== Estimates with Intercepts ============================="; print; /* Loop over the assets */ pmat = -999 * zeros(rows(vn_z)-1,2); @ initializes alphas and betas as N times 2 matrix @ j = 1; do while j <= rows(vn_z)-1; @{ vnam, m, b, stb, vc, stderr, sigma, cx, rsq, resid, dwstat } = @ { nix, nix, b, nix, nix, nix, nix, nix, nix, nix, nix } = ols(path_dat $+n_dat, vn_z[j], vn_z[rows(vn_z)]); print "==============================================================================="; print; pmat[j,.] = b' ; j = j+1; endo; @======================= SURE ESTIMATION ============================================================@ Z = loadd(path_dat $+n_dat); R_m_bar = meanc(Z[., rows(vn_z)]); {pmat_s, SIGMA, VC_pv, pv, s_pv, t_pv} = sure(Z[.,1:rows(vn_Z)-1], Z[., rows(vn_z)]); t_pmat_s = reshape(t_pv,rows(pmat_s), cols(pmat_s)); N_asset = rows(pmat_s); save path = ^path_fmt pmat, pmat_s, SIGMA, VC_pv, pv, s_pv, t_pv, R_m_bar ; @ saves variables as Gauss matrix file @ R_alpha = zeros(N_asset,2*N_asset); for i (1, N_asset, 1); R_alpha[i,2*i-1] = 1 ; endfor; alpha = R_alpha * pv; VC_alpha = R_alpha * vc_pv * R_alpha'; W_alpha = alpha'invpd(VC_alpha) * alpha; {beta_id,lam_id} = id_simple(pmat_s, R_m_bar); save path = ^path_fmt beta_id, lam_id ; @ saves variabel as Gauss matrix file @ p_out = pmat_s[.,1]~t_pmat_s[.,1]~pmat_s[.,2]~t_pmat_s[.,2]; d_tv_a = abs(t_pmat_s[.,1]) .> abs(cdfNi(0.025)); @ dummy significan t-vals for alpha@ print; print;"==============================================================================="; print "=================== SURE ESTIMATION of the CAPM ==============================="; print; print "Number of Assets";; N_asset; print; print " Reduced Form Parameter Estimates"; print " alpha t-alpha beta t-beta"; p_out; print; print "Number of alphas significantly different from zero:";; sumc(d_tv_a); print " Wald Test of alpha = 0:";; W_alpha; print " p-val.:";; cdfChic(W_alpha, N_asset); print; print " Estimated Reliability Ratio:";; lam_id; print; print "Identified Betas"; beta_id'; print $vn_z[1:rows(vn_z)-1]'; print; print; @============== Minimum Distance Estimation of CAPM with Measurement Error ===========@ theta_sv = beta_id|1 ; @ starting values from simleidentification scheme @ _opgtol = 1e-5; _opparnm = trimr(vn_z,0,1)|"LAMBDA" ; __output = 0; __title = "Minimum Distance Estimation of CAPM with Measurement Error"; { theta_md,fmin,g,retcode } = optmum(&md,theta_sv); __output = 2; call optprt(theta_md,fmin,g,retcode); G0 = gradp(&fct,theta_md); VC_theta = invpd(G0' invpd(vc_pv) * G0) ; std_theta = sqrt(diag(VC_theta)); t_theta = theta_md./std_theta ; md_out = theta_md~std_theta~t_theta ; t_diff = (trimr(theta_md,rows(theta_md)-1,0)-1)/trimr(std_theta,rows(theta_md)-1,0); print "Minimum Distance Betas"; theta_md[1:rows(theta_md)-1]'; print $vn_z[1:rows(vn_z)-1]'; print; print "====== Minumum Distance Parameter Estimates ================"; print " theta std-theta t-theta"; md_out; print; print " Minimum Distance Reliability Ratio:";; theta_md[rows(theta_md)]; print; __output = 0; _opparnm = trimr(vn_z,0,1) ; __title = "Minimum Distance Estimation of CAPM with Measurement Error: Reliability = 1"; { theta_0,fmin_0,g_0,retcode } = optmum(&md0,trimr(theta_md,0,1)); __output = 2; @call optprt(theta_0,fmin_0,g_0,retcode);@ MD_diff = fmin_0 - fmin ; @ difference between md CAPM without intercept and without measurement error vs CAPM with measutement error @ print; "---------------------------------------------------------"; print; " Chi-Square Test no measurement error:";; MD_diff; print; " df:";; 1; print; " p-val.:";; cdfChic(MD_diff, 1); print; " t-Test no measurement error:";; (trimr(theta_md,rows(theta_md)-1,0)-1)/trimr(std_theta,rows(theta_md)-1,0); print; " p-val.";; 2*cdfnc(abs(t_diff)); print; "---------------------------------------------------------"; print; " Chi-Square Test CAPM vs lin. pred. model:";; fmin; df_0 = rows(pv) - rows(theta_md); @ difference in number of parameters SURE vs MD @ print; " df:";; df_0; print; " p-val.:";; cdfChic(fmin, df_0); __output = 0; _opparnm = trimr(vn_z,0,1)|"ROOT_L" ; __title = "Minimum Distance Estimation of CAPM with Measurement Error under restriction"; { theta_mdr,fminr,gr,retcode } = optmum(&mdr,theta_sv); __output = 2; call optprt(theta_mdr,fminr,gr,retcode); print; print "MD (restricted) reliability ratio";; theta_mdr[rows(theta_mdr)]^2;