* Hausman Test for Consumption Function
*
* Keywords:
* regression, 2sls, consumption, function, iv, hausman, wu
*
* Description:
* We illustrate how to examine endogeneity of a variable in Consumption
* Function Model by using Wu and Hausman's tests
*
* Author(s):
* Noel Roy
* Skif Pankov
*
* Source:
* William H. Greene, Econometric Analysis - 7th Edition
* Pearson International Edition, Chapter 8, Example 8.7 (page 277)
*
* Reading the datafile and naming the variables, specifying to ignore the
* first line of the file
read (TableF5-2.shd) year qtr gdp c i g y / skiplines=1
* Generating lagged values of consumption and dpi as instumental variables
genr lagc=lag(c)
genr lagy=lag(y)
time 1950.1 4
* Because we have no data for the lagged insrumental variables for 1950.1,
* we must discard this observation
sample 1950.2 2000.4
* Method 1:
*
* Estimation using the consistent estimator (IV) under both the null and the
* alternative hypotheses is performed using the inst command. Instrumental
* variables are named in parentheses. We also specify to save the vector of
* IV estimates in b1, the covariance matrix of the estimates in v1, and a
* consistent estimator of the variance of the equation error in sigiv
inst c y (lagc lagy) / coef=b1 pcov cov=v1
gen1 sigiv=$sig2
* Estimating using the efficient estimator (ols) under the null, and saving the
* vector of ols estimates in b0, the covariance matrix of the estimates in v0,
* and a consistent estimator of the variance of the equation error in sigols
ols c y / coef=b0 cov=v0
gen1 sigols=$sig2
* The hausmann statistic uses the same estimate s2 for the variance of the
* disturbances. The saved covariance matrices v0 and v1, however, uses
* their respective extimates sigols and sigiv, so we must correct one of
* these estimates
matrix v1=sigols/sigiv*v1
* Computing the Hausman specification test statistic
sample 1 2
genr d=b1-b0
matrix vd=v1-v0
matrix h=(d(1)**2) / vd(1,1)
* The statistic h is distributed chi-square with 1 degree of freedom under the
* null hypothesis
print h
distrib h /type=chi df=1
* Method 2 (Wu statistic):
sample 1950.2 2000.4
* Getting the predicted values in a regression of y on lagy and lagc
?ols y lagy lagc / predict=yhat
* Regressing cons on gdp and yhat
?ols c y yhat
* Testing the null hypothesis that the coefficient of yhat is zero
test yhat
stop