IV in Stata and MATLAB

Problem

Use schoolingsml.dta for Stata and schoolingsml.mat for MATLAB

a) Find the IV estimator and the standard errors explaining lwage76 using ed76 and exp76 using momed as an instrument for ed76 in Stata and in MATLAB. In MATLAB,

  • y is lwage76
  • X is (1 ed76 exp76)
  • Z1 is (1 momed exp76)
  • b) Find the same result by using OLS twice both in Stata and in MATLAB

c) Find the GIV estimator and the standard errors explaining lwage76 using ed76 and exp76 using momed and daded as an instrument for ed76 in Stata and in MATLAB. In MATLAB,

  • y is lwage76
  • X is (1 ed76 exp76)
  • Z2 is (1 momed daded exp76)

Solution

  • a)
  • Stata:

MATLAB:

  • bIV = inv(Z1'*X)*Z1'*y
  • e = y - X*bIV;
  • s2 = e'*e/3007
  • PZ1 = Z1'*inv(Z1'*Z1)*Z1;
  • VarbIV = s2*inv(X'*PZ1*X)
  • sebIV = sqrt(diag(VarbIV))
  • Note: since you have the same number of instruments as endogenous variables, the generalized IV estimator will be the same as the IV estimator. Try it, bGIV = inv(X’*PZ1*X)*X’*PZ1'*y.
  • b)

STATA

  • regr ED76 EXP76 MOMED
  • predict fitted
  • regr LWAGE76 fitted EXP76
  • Same result

MATLAB

  • b1 = inv(Z1'*Z1)*Z1'*X
  • fit = Z1*b1;
  • b2sls = inv(fit'*fit)*fit'*y
  • Same
  • c)

STATA

MATLAB:

  • PZ2 = Z2'*inv(Z2'*Z2)*Z2;
  • bGIV = inv(X’*PZ2*X)*X’*PZ2'*y
  • e = y - X*bGIV;
  • s2 = e'*e/3007
  • VarbGIV = s2*inv(X'*PZ2*X)
  • sebGIV = sqrt(diag(VarbGIV))