RATS 11
RATS 11

ADAPTIVE.RPF is adapted from Pagan and Ullah(1999), pp 250-251. It demonstrates the use of the DENSITY instruction for adjusting the covariance matrix of a least-squares estimator for a non-Normal residual density. It also makes use of the instruction MCOV for several key calculations.

 

 For the regression equation

\begin{equation} y_t = X_t \beta + u_t \end{equation}

if the density of \(u\) is the (unknown) \(f\), the derivative of the log likelihood with respect to \(\beta\) is

\begin{equation} - \sum {X_t \left( {{{f'\left( {u_t } \right)} \mathord{\left/ {\vphantom {{f'\left( {u_t } \right)} {f\left( {u_t } \right)}}} \right. } {f\left( {u_t } \right)}}} \right)} \equiv - \sum {X_t } \psi _t \label{eq:adaptive_scores} \end{equation}

The adaptive kernel estimator is a two-step estimator which starts with OLS and uses kernel estimates of

\begin{equation} \psi _t = {{f'\left( {u_t } \right)} \mathord{\left/ {\vphantom {{f'\left( {u_t } \right)} {f\left( {u_t } \right)}}} \right. } {f\left( {u_t } \right)}} \end{equation} 

Because we need to compute the density at the given data points, this uses GRID=INPUT with the RESIDS providing the evaluation points. This uses TYPE=GAUSS because we need a differentiable kernel to get estimates of the density derivative.

 

linreg(robusterrors) price / resids

# sqft yard pool lajolla baths firepl irreg sprink view lsqft $

 lyard constant

density(type=gauss,derives=f1,grid=input) resids / resids fu

set psi = f1/fu

 

The second step is to compute the change in \(\beta\) that would push \eqref{eq:adaptive_scores} towards zero. A “method of scoring” step would take this step as (minus) the information matrix times the gradient. Assuming that \(u\) and \(X\) are independent, the information matrix can be estimated as

\begin{equation} \left( {{1 \mathord{\left/ {\vphantom {1 T}} \right. } T}} \right)\left( {\sum {\psi _{_t }^2 } } \right)\left( {\sum {X_t ^\prime } X_t } \right) \end{equation}

which can be computed using MCOV with the NOZUDEP option:

 

mcov(lastreg,matrix=ibxx,nozudep) / psi

 

If you’re not willing to assume that, you could use a BHHH estimate of

\begin{equation} \sum {X_t ^\prime } \psi _t^2 X_t \end{equation}

This is computable using MCOV with ZUDEP, and is needed at any rate to estimate the covariance matrix, as it's the center of the "sandwich". This also computes the gradient, which is \(T\) times the mean vector of the products of PSI with the regressors. LINREG with CREATE is then used to display the regression output with the adjusted beta and sandwich estimator of the covariance matrix.

 

mcov(lastreg,matrix=ib,meanvector=mv) / psi

compute d=mv*%nobs

linreg(create,lastreg,form=chisquared,$

  title="Adaptive Kernel Estimator",$

  coeffs=%beta-inv(ibxx)*d,covmat=inv(ibxx)*ib*inv(ibxx))

 

Full Program

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))
 

Output


Linear Regression - Estimation by Least Squares

With Heteroscedasticity-Consistent (Eicker-White) Standard Errors

Dependent Variable PRICE

Usable Observations                        59

Degrees of Freedom                         47

Centered R^2                        0.8082786

R-Bar^2                             0.7634077

Uncentered R^2                      0.9631736

Mean of Dependent Variable       228.62942373

Std Error of Dependent Variable  112.43586040

Standard Error of Estimate        54.68965491

Sum of Squared Residuals         140575.04263

Log Likelihood                      -313.1082

Durbin-Watson Statistic                1.9736


 

    Variable                        Coeff      Std Error      T-Stat      Signif

************************************************************************************

1.  SQFT                             0.242854     0.077900      3.11750  0.00182390

2.  YARD                             0.007773     0.002060      3.77285  0.00016139

3.  POOL                            31.014472    17.314004      1.79129  0.07324611

4.  LAJOLLA                        102.256649    15.846660      6.45288  0.00000000

5.  BATHS                           25.893292    22.196190      1.16656  0.24338619

6.  FIREPL                          28.777792    18.100197      1.58992  0.11185376

7.  IRREG                           45.311789    20.222589      2.24065  0.02504861

8.  SPRINK                          48.618835    14.870864      3.26940  0.00107775

9.  VIEW                            28.937609    15.991109      1.80961  0.07035688

10. LSQFT                         -964.002131   394.273886     -2.44501  0.01448496

11. LYARD                          -95.490573    47.917554     -1.99281  0.04628227

12. Constant                      2997.279347  1168.200087      2.56572  0.01029606


 

Linear Regression - Estimation by Adaptive Kernel Estimator

Dependent Variable PRICE

Usable Observations                        59

Degrees of Freedom                         47

Mean of Dependent Variable       228.62942373

Std Error of Dependent Variable  112.43586040

Standard Error of Estimate        61.40143880

Sum of Squared Residuals         177196.42427

Durbin-Watson Statistic                2.0239


 

    Variable                        Coeff      Std Error      T-Stat      Signif

************************************************************************************

1.  SQFT                             0.220717     0.046762      4.72006  0.00000236

2.  YARD                             0.007096     0.001942      3.65482  0.00025736

3.  POOL                             3.419658    15.565039      0.21970  0.82610387

4.  LAJOLLA                         76.955584    13.387061      5.74850  0.00000001

5.  BATHS                           -8.206580    11.150998     -0.73595  0.46176099

6.  FIREPL                          25.003740    11.442324      2.18520  0.02887435

7.  IRREG                           18.554536    15.634321      1.18678  0.23531347

8.  SPRINK                          42.826452    14.548647      2.94367  0.00324343

9.  VIEW                            42.323711    14.596797      2.89952  0.00373734

10. LSQFT                         -650.159864   242.581484     -2.68017  0.00735846

11. LYARD                         -107.616971    49.684711     -2.16600  0.03031136

12. Constant                      2173.193469   662.942126      3.27810  0.00104507


 


Copyright © 2025 Thomas A. Doan