* * ADAPTIVE.PRG * Manual Example 12.8 * Adapted from Pagan and Ullah, Nonparametric Econometrics, Cambridge, 1999, * pp 250-251. * open data housing.csv data(format=prn,org=columns) 1 59 price age aircon baths bedrms cond corner culd dish $ fence firepl floors garage irreg lajolla lndry patio pool rooms sprink sqft view yard set lsqft = log(sqft)/log(10) set lyard = log(yard)/log(10) * * Estimate linear regression with White standard errors * linreg(robusterrors) price / resids # sqft yard pool lajolla baths firepl irreg sprink view lsqft lyard constant * * Adaptive kernel estimator. For the regression equation y=Xb+u, if the density * of u is the (unknown) f, the gradient of the log likelihood is - sum {x(t) * f'(u(t))/f(u(t)}. The adaptive kernel estimator is a two-step estimator * starting with OLS and using kernel estimates of psi=f'/f. * * We need to compute the density at the given data points, so grid=input is used * with the resids providing the evaluation points. * density(type=gauss,derives=f1,grid=input) resids / resids fu set psi = f1/fu * * The information matrix is computed by using MCOV with the NOZUDEP option as u * and X are assumed to be independent. * mcov(lastreg,matrix=ibxx,nozudep) / psi * * The same but with ZUDEP is needed for the center of the "sandwich". We also * need the gradient, which will be %nobs * the mean vector of the products of psi * with the regressors. * mcov(lastreg,matrix=ib,meanvector=mv) / psi compute d=mv*%nobs * * Display the regression output with the adjusted beta and sandwich estimator of * the covariance matrix. * linreg(create,lastreg,form=chisquared,title="Adaptive Kernel Estimator",$ coeffs=%beta-inv(ibxx)*d,covmat=inv(ibxx)*ib*inv(ibxx))