/* ** Minimum-Distance Exercise ** ** Model is given : ** y = beta1 + beta2*x_2 + beta3*x_3 + e , ** where beta1 = theta2, beta2 = theta1*theta2, beta3 = theta1*(1-theta2). ** ** This program estimate theta1 and theta2 by MD. ** Enjoy! */ new ; @ Generate data @ tt = 100 ; kk = 3 ; theta1 = 4; theta2 = 0.6; beta1 = theta2 ; beta2 = theta1*theta2 ; beta3 = theta1*(1-theta2) ; seed = 1; xx = ones(tt,1)~(3*rndns(tt,kk-1,seed)); yy = beta1 + beta2*xx[.,2] + beta3*xx[.,3] + rndns(tt,1,seed); @ OLS estimates @ bb = invpd(xx'xx)*(xx'yy) ; s2 = (yy-xx*bb)'(yy-xx*bb)/(tt-kk) ; v = s2*invpd(xx'xx) ; @ minimum distance procedure @ library optmum; #include optmum.ext; optset ; proc g(thet) ; local gg ; gg = thet[2]|(thet[1]*thet[2])|(thet[1]*(1-thet[2])) ; retp( gg ) ; endp ; proc f(thet) ; local ff ; ff = (bb-g(thet))'invpd(v)*(bb-g(thet)) ; retp( ff ) ; endp ; thet0 = {0.1,0.5} ; _opgtol = 1e-4; _opstmth = "bfgs, half"; __output = 0 ; {theta,func,grad,retcode} = optmum(&f,thet0) ; @ Covariance matrix @ g_gra = gradp(&g,theta); cov = invpd(g_gra'invpd(v)*g_gra) ; se = sqrt(diag(cov)); format /rd 10,4 ; "" ; "MD Estimation Results" ; "------------------------" ; "" ; " coeff. std. err. t-st " ; theta~se~(theta./se); bb; "" ;