# 5 IV estimation of Single-Equation Linear Models

Also available in Stata and Python versions

## 5.1 Example 5.3

``````library(wooldridge)
library(AER)
library(haven)``````

Parents’ and Husband’s Education as IVs

``summary(lm(lwage ~ exper + expersq + educ, data=mroz))``
``````##
## Call:
## lm(formula = lwage ~ exper + expersq + educ, data = mroz)
##
## Residuals:
##      Min       1Q   Median       3Q      Max
## -3.08404 -0.30627  0.04952  0.37498  2.37115
##
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.5220406  0.1986321  -2.628  0.00890 **
## exper        0.0415665  0.0131752   3.155  0.00172 **
## expersq     -0.0008112  0.0003932  -2.063  0.03974 *
## educ         0.1074896  0.0141465   7.598 1.94e-13 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.6664 on 424 degrees of freedom
##   (325 observations deleted due to missingness)
## Multiple R-squared:  0.1568, Adjusted R-squared:  0.1509
## F-statistic: 26.29 on 3 and 424 DF,  p-value: 1.302e-15``````
``summary(IV1 <- ivreg(lwage ~ exper + expersq + educ | motheduc + fatheduc + huseduc + exper + expersq, data = mroz))``
``````##
## Call:
## ivreg(formula = lwage ~ exper + expersq + educ | motheduc + fatheduc +
##     huseduc + exper + expersq, data = mroz)
##
## Residuals:
##      Min       1Q   Median       3Q      Max
## -3.08378 -0.32135  0.03538  0.36934  2.35829
##
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.1868572  0.2853959  -0.655 0.512997
## exper        0.0430973  0.0132649   3.249 0.001250 **
## expersq     -0.0008628  0.0003962  -2.178 0.029976 *
## educ         0.0803918  0.0217740   3.692 0.000251 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.6693 on 424 degrees of freedom
## Multiple R-Squared: 0.1495,  Adjusted R-squared: 0.1435
## Wald test: 11.52 on 3 and 424 DF,  p-value: 2.817e-07``````
``````ols <- lm(educ ~motheduc + fatheduc + huseduc + exper + expersq, data=subset(mroz, !is.na(wage)))
linearHypothesis(ols, c("motheduc=0" , "fatheduc=0" , "huseduc=0"))``````
``````## Linear hypothesis test
##
## Hypothesis:
## motheduc = 0
## fatheduc = 0
## huseduc = 0
##
## Model 1: restricted model
## Model 2: educ ~ motheduc + fatheduc + huseduc + exper + expersq
##
##   Res.Df    RSS Df Sum of Sq      F    Pr(>F)
## 1    425 2219.2
## 2    422 1274.4  3    944.85 104.29 < 2.2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1``````

## 5.2 Example 5.4

Parents’ and Husband’s Education as IVs, cont’d

``summary(IV2 <- ivreg(lwage ~ educ +  exper + expersq + kidslt6 + kidsge6 | motheduc + fatheduc + huseduc + exper + expersq + kidslt6 + kidsge6, data = mroz))``
``````##
## Call:
## ivreg(formula = lwage ~ educ + exper + expersq + kidslt6 + kidsge6 |
##     motheduc + fatheduc + huseduc + exper + expersq + kidslt6 +
##         kidsge6, data = mroz)
##
## Residuals:
##      Min       1Q   Median       3Q      Max
## -3.07061 -0.31785  0.03213  0.37457  2.34888
##
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.1315325  0.3038534  -0.433 0.665322
## educ         0.0798678  0.0223575   3.572 0.000395 ***
## exper        0.0414939  0.0134453   3.086 0.002161 **
## expersq     -0.0008576  0.0003972  -2.159 0.031409 *
## kidslt6     -0.0313332  0.0861049  -0.364 0.716118
## kidsge6     -0.0182224  0.0271427  -0.671 0.502360
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.6705 on 422 degrees of freedom
## Multiple R-Squared: 0.1505,  Adjusted R-squared: 0.1404
## Wald test: 7.084 on 5 and 422 DF,  p-value: 2.242e-06``````
``linearHypothesis(IV2, c("kidslt6=0" , "kidsge6=0"))``
``````## Linear hypothesis test
##
## Hypothesis:
## kidslt6 = 0
## kidsge6 = 0
##
## Model 1: restricted model
## Model 2: lwage ~ educ + exper + expersq + kidslt6 + kidsge6 | motheduc +
##     fatheduc + huseduc + exper + expersq + kidslt6 + kidsge6
##
##   Res.Df Df  Chisq Pr(>Chisq)
## 1    424
## 2    422  2 0.6114     0.7366``````
``anova(IV1, IV2,  vcov=vcov(IV2))``
``````## Wald test
##
## Model 1: lwage ~ exper + expersq + educ | motheduc + fatheduc + huseduc +
##     exper + expersq
## Model 2: lwage ~ educ + exper + expersq + kidslt6 + kidsge6 | motheduc +
##     fatheduc + huseduc + exper + expersq + kidslt6 + kidsge6
##   Res.Df Df      F Pr(>F)
## 1    424
## 2    422  2 0.3057 0.7368``````

LM test

``````uhat <- resid(IV1)
summary(IV3u <- ivreg(uhat ~ educ +  exper + expersq + kidslt6 + kidsge6 | motheduc + fatheduc + huseduc + exper + expersq + kidslt6 + kidsge6, data = subset(mroz, !is.na(wage))))``````
``````##
## Call:
## ivreg(formula = uhat ~ educ + exper + expersq + kidslt6 + kidsge6 |
##     motheduc + fatheduc + huseduc + exper + expersq + kidslt6 +
##         kidsge6, data = subset(mroz, !is.na(wage)))
##
## Residuals:
##      Min       1Q   Median       3Q      Max
## -3.07061 -0.31785  0.03213  0.37457  2.34888
##
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)
## (Intercept)  5.532e-02  3.039e-01   0.182    0.856
## educ        -5.240e-04  2.236e-02  -0.023    0.981
## exper       -1.603e-03  1.345e-02  -0.119    0.905
## expersq      5.169e-06  3.972e-04   0.013    0.990
## kidslt6     -3.133e-02  8.610e-02  -0.364    0.716
## kidsge6     -1.822e-02  2.714e-02  -0.671    0.502
##
## Residual standard error: 0.6705 on 422 degrees of freedom
## Multiple R-Squared: 0.001115,    Adjusted R-squared: -0.01072
## Wald test: 0.1223 on 5 and 422 DF,  p-value: 0.9874``````
``````LM <- summary(IV3u)\$r.squared * nobs(IV3u)
LM``````
``## [1] 0.4773772``
``pchisq(LM, 2, lower.tail = FALSE)``
``## [1] 0.7876601``

** Hetroskedasticity-Robust Inference pp106 **

``coeftest(IV1, vcovHC(IV1, type="HC1"))``
``````##
## t test of coefficients:
##
##                Estimate  Std. Error t value  Pr(>|t|)
## (Intercept) -0.18685722  0.30126251 -0.6202 0.5354283
## exper        0.04309732  0.01530642  2.8156 0.0050951 **
## expersq     -0.00086280  0.00042166 -2.0462 0.0413549 *
## educ         0.08039176  0.02170330  3.7041 0.0002402 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1``````

Hteroskedasticity robust F test, page 107 (F=.25 & p-value=.781)

``coeftest(IV2, vcovHC(IV2, type="HC1"))``
``````##
## t test of coefficients:
##
##                Estimate  Std. Error t value  Pr(>|t|)
## (Intercept) -0.13153245  0.32063399 -0.4102 0.6818482
## educ         0.07986781  0.02246128  3.5558 0.0004195 ***
## exper        0.04149393  0.01544625  2.6863 0.0075091 **
## expersq     -0.00085763  0.00042121 -2.0361 0.0423619 *
## kidslt6     -0.03133324  0.10139675 -0.3090 0.7574617
## kidsge6     -0.01822245  0.02835793 -0.6426 0.5208409
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1``````

//LM test page 107

``````dmroz <- subset(mroz, !is.na(wage))
uhat <- resid(IV1 <- ivreg(lwage ~ exper + expersq + educ | motheduc + fatheduc + huseduc + exper + expersq, data = mroz))
u_klt6 <- resid(ivreg(kidslt6 ~ exper + expersq + educ | motheduc + fatheduc + huseduc + exper + expersq, data=mroz))
u_kage6 <- resid(ivreg(kidsge6 ~ exper + expersq + educ | motheduc + fatheduc + huseduc + exper + expersq, data=mroz))

df <- data.frame(cbind(lwage=mroz\$lwage, uhat, u_klt6, u_kage6))``````
``````## Warning in cbind(lwage = mroz\$lwage, uhat, u_klt6, u_kage6): number of rows of
## result is not a multiple of vector length (arg 2)``````
``````df['one']=1
df <- subset(df, !is.na(lwage))

summary(long <- lm(one ~ u_kage6:uhat + u_klt6:uhat + 0, data=df))``````
``````##
## Call:
## lm(formula = one ~ u_kage6:uhat + u_klt6:uhat + 0, data = df)
##
## Residuals:
##    Min     1Q Median     3Q    Max
## 0.7298 0.9896 0.9992 1.0078 1.3243
##
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)
## u_kage6:uhat -0.02840    0.05655  -0.502    0.616
## uhat:u_klt6  -0.11502    0.16065  -0.716    0.474
##
## Residual standard error: 1.001 on 426 degrees of freedom
## Multiple R-squared:  0.002027,   Adjusted R-squared:  -0.002658
## F-statistic: 0.4327 on 2 and 426 DF,  p-value: 0.649``````
``````LM <- summary(long)\$r.squared * nobs(long)
LM``````
``## [1] 0.8676851``
``pchisq(LM, 2, lower.tail = FALSE)``
``## [1] 0.6480143``

## 5.3 Example 5.5

IQ and KWW as indicator of Ability

``````nls80 <- read_dta("nls80.dta")
summary(ivreg(lwage ~ exper + tenure + married + south + urban + black + educ + iq | kww + exper + tenure + married + south + urban + black + educ, data=nls80))``````
``````##
## Call:
## ivreg(formula = lwage ~ exper + tenure + married + south + urban +
##     black + educ + iq | kww + exper + tenure + married + south +
##     urban + black + educ, data = nls80)
##
## Residuals:
##       Min        1Q    Median        3Q       Max
## -2.095561 -0.224017  0.006572  0.234495  1.398914
##
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)
## (Intercept)  4.592453   0.325781  14.097  < 2e-16 ***
## exper        0.014420   0.003321   4.342 1.56e-05 ***
## tenure       0.010456   0.002601   4.020 6.30e-05 ***
## married      0.200690   0.040678   4.934 9.56e-07 ***
## south       -0.051553   0.031128  -1.656  0.09803 .
## urban        0.176706   0.028212   6.264 5.75e-10 ***
## black       -0.022561   0.073960  -0.305  0.76040
## educ         0.025032   0.016607   1.507  0.13206
## iq           0.013047   0.004934   2.644  0.00832 **
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.3807 on 926 degrees of freedom
## Multiple R-Squared:  0.19,   Adjusted R-squared: 0.183
## Wald test: 36.96 on 8 and 926 DF,  p-value: < 2.2e-16``````