Professional Documents
Culture Documents
2 Sls
2 Sls
clear matrix
use http://www.stata-press.com/data/imeus/griliches, clear
gen cons= 1
/* The Z matrix is the X matrix but with the endogenous variable(s) replaced
with its/their instrument(s) */
mkmat cons s expr tenure rns smsa _I* med kww age mrt, mat(Z)
mat dir
mat ZTZ= ZT * Z
mat ZTX= ZT * X
/* Next, create one matrix that contains (in order) the values of iq
in the Xhat matrix, the predicted value of iq based on all exogenous variables,
and iq from the original X matrix */
matrix Xhatiq_iqhat_iqx= Xhatiq, iqhat, X[1.. `e(N)', 2]
matrix list Xhatiq_iqhat_iqx
/* Can see above that the predicted values of iq are 1) based on a regression
of iq on all the exogenous variables
(i.e., instruments and exogenous regressors) 2) agree to the values of
the iq variable used in the Xhat matrix and 3) that these values are different
from the observed values of iq in the X matrix. The Xhat matrix has replaced
the endogenous, observed values of iq with their predictions using the
instrumental variable(s). */
matrix d
local names1: colnames Xhat
display "`names1'"
local names3: colnames X
display "`names3'"
/* The Z matrix has 16 columns, and both the X and Xhat matrix have 13
columns. You can see from the above that 1) the X and Xhat matrix contain
the same values for the exogenous regressors and 2) The endogenous iq
variable has been replaced in the Xhat matrix by its prediction from
an OLS regression model based on its instruments and all of the other
exogenous variables. */
matrix list B