options charcode nocenter linesize=80; data nairu; input obs y unemp; cards; 1 0 4.10000 2 0 4.23333 3 0 4.93333 4 0 6.30000 5 1 7.36667 6 1 7.33333 7 1 6.36667 8 0 5.83333 9 0 5.10000 10 0 5.26667 11 0 5.60000 12 0 5.13333 13 1 5.23333 14 1 5.53333 15 0 6.26667 16 0 6.80000 17 1 7.00000 18 0 6.76667 19 0 6.20000 20 0 5.63333 21 0 5.53333 22 1 5.56667 23 1 5.53333 24 1 5.76667 25 0 5.73333 26 0 5.50000 27 0 5.56667 28 0 5.46667 29 1 5.20000 30 0 5.00000 31 0 4.96667 32 1 4.90000 33 1 4.66667 34 1 4.36667 35 1 4.10000 36 1 3.86667 37 0 3.83333 38 1 3.76667 39 1 3.70000 40 1 3.83333 41 1 3.83333 42 1 3.80000 43 1 3.90000 44 1 3.73333 45 1 3.56667 46 1 3.53333 47 0 3.40000 48 1 3.40000 49 1 3.43333 50 0 3.56667 51 1 3.56667 52 0 4.16667 53 0 4.76667 54 0 5.16667 55 0 5.83333 56 0 5.93333 57 0 5.9000 58 0 6.0333 59 0 5.9333 60 0 5.7667 61 1 5.7000 62 1 5.5667 63 1 5.3667 64 1 4.9333 65 1 4.9333 66 1 4.8000 67 1 4.7667 68 1 5.1333 69 0 5.2000 70 0 5.6333 71 0 6.6000 72 0 8.2667 73 0 8.8667 74 1 8.4667 75 0 8.3000 76 0 7.7333 77 1 7.5667 78 0 7.7333 79 0 7.7667 80 1 7.5000 81 1 7.1333 82 1 6.9000 83 1 6.6667 84 1 6.3333 85 1 6.0000 86 1 6.0333 87 1 5.9000 88 1 5.8667 89 1 5.7000 90 0 5.8667 91 1 5.9667 92 0 6.3000 93 0 7.3333 94 1 7.6667 95 0 7.4000 96 0 7.4333 97 0 7.4000 98 0 7.4000 99 0 8.2333 100 0 8.8333 101 0 9.4333 102 0 9.9000 103 1 10.6667 104 1 10.3667 105 1 10.1333 106 1 9.3667 107 0 8.5333 108 0 7.8667 109 0 7.4333 110 0 7.4333 111 1 7.3000 112 0 7.2333 113 0 7.30000 114 1 7.20000 115 0 7.03333 116 0 7.03333 117 1 7.16667 118 0 6.96667 119 1 6.83333 120 0 6.60000 121 1 6.26667 122 1 6.00000 123 1 5.83333 124 1 5.70000 125 0 5.46667 126 0 5.46667 127 0 5.33333 128 1 5.20000 129 1 5.23333 130 1 5.23333 131 0 5.36667 132 1 5.26667 133 0 5.26667 134 0 5.56667 135 0 6.00000 136 0 6.53333 137 0 6.73333 138 0 6.73333 139 0 6.96667 140 0 7.26667 141 0 7.50000 142 0 7.50000 143 0 7.30000 144 0 7.03333 145 0 6.93333 146 1 6.73333 147 0 6.53333 148 1 6.60000 149 1 6.20000 150 0 5.96667 ; proc iml; start mle; use nairu; read all var{y} into y; read all var{unemp} into xs; print , "Newton-Raphson Estimation of NAIRU Logit Model"; /* Starting values for beta1 and beta2 */ beta = {0,0}; crit = 1; n=150; ones=j(n,1,1); x=ones||xs; result = j(10,7,0); /* Use Newton's method to maximize likelihood function.*/ do iter = 1 to 10 while (crit > 1.0e-10); v=x*beta; bigf1=1/(1 + exp(v)); bigf2=1/(1 + exp(-v)); littlef=exp(-v)#(bigf2##2); logl=sum(y#log(bigf2) + (1-y)#log(1-bigf2)); gx=x#(y#bigf1 - (1-y)#bigf2); gt=gx[+,]; g=gt`; h=-x`*(x#littlef); /* The Newton two step */ db = -inv(h)*g; betanew = beta + db; crit = sqrt(ssq(betanew - beta)); /* Place the result of this iteration in the result matrix */ result[iter,] = iter||(g`)||(beta`)||crit||logL; beta = betanew; end; cnames = {iter,g1,g2,beta1,beta2,crit,logl}; print "Results of Newton Iterations" result [colname=cnames]; cov = -inv(h); * cov from Hessian; print "Beta Coefficients" beta; print "Hessian Form of Covariance Matrix" cov; finish; run mle; quit;