# 9 Simultaneous Equations Models

Also available in Stata and Python versions

## 9.1 Example 9.5

``````library(wooldridge)
library(stargazer)
library(AER)``````

Labor Supply for Married, Working Women

``````OLShr <- lm(hours ~ lwage + educ + age + kidslt6 + kidsge6 + nwifeinc, data=mroz)
IVhr <- ivreg(hours ~ lwage + educ + age + kidslt6 + kidsge6 + nwifeinc |  exper + expersq + + educ + age + kidslt6 + kidsge6 + nwifeinc, data=mroz)

stargazer(OLShr, IVhr, keep.stat=c("n", "rsq", "adj.rsq"), no.space=TRUE, type="text")``````
``````##
## =========================================
##                  Dependent variable:
##              ----------------------------
##                         hours
##                   OLS       instrumental
##                               variable
##                   (1)            (2)
## -----------------------------------------
## lwage           -17.408     1,544.819***
##                 (54.215)      (480.739)
## educ            -14.445      -177.449***
##                 (17.968)      (58.143)
## age              -7.730        -10.784
##                 (5.529)        (9.577)
## kidslt6       -342.505***     -210.834
##                (100.006)      (176.934)
## kidsge6       -115.021***      -47.557
##                 (30.829)      (56.918)
## nwifeinc         -4.246        -9.249
##                 (3.656)        (6.481)
## Constant      2,114.697***  2,432.198***
##                (340.131)      (594.172)
## -----------------------------------------
## Observations      428            428
## R2               0.067         -1.773
## =========================================
## Note:         *p<0.1; **p<0.05; ***p<0.01``````
``````mroz2<- subset(mroz, !is.na(wage))
uhat <- resid(IVhr)
summary(ureg <- lm(uhat ~ educ + age + kidslt6 + kidsge6 + nwifeinc + exper + expersq, data=mroz2))``````
``````##
## Call:
## lm(formula = uhat ~ educ + age + kidslt6 + kidsge6 + nwifeinc +
##     exper + expersq, data = mroz2)
##
## Residuals:
##     Min      1Q  Median      3Q     Max
## -4391.5  -644.9   -20.3   533.1  8103.5
##
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)
## (Intercept) 177.4856   621.6837   0.285    0.775
## educ          0.3573    29.4878   0.012    0.990
## age          -3.4411    10.5754  -0.325    0.745
## kidslt6      -8.5741   173.0567  -0.050    0.961
## kidsge6       2.4540    54.4756   0.045    0.964
## nwifeinc      0.8964     6.4836   0.138    0.890
## exper       -15.8841    26.1182  -0.608    0.543
## expersq       0.6408     0.7847   0.817    0.415
##
## Residual standard error: 1302 on 420 degrees of freedom
## Multiple R-squared:  0.002005,   Adjusted R-squared:  -0.01463
## F-statistic: 0.1205 on 7 and 420 DF,  p-value: 0.9969``````
``````LM <- summary(ureg)\$r.squared * nobs(ureg)
LM``````
``## [1] 0.8581694``
``pchisq(LM, df=1, lower.tail = FALSE)``
``## [1] 0.3542515``
``summary(OLSwg <- lm(lwage ~ educ + age + kidslt6 + kidsge6 + nwifeinc + exper + expersq, data=mroz))``
``````##
## Call:
## lm(formula = lwage ~ educ + age + kidslt6 + kidsge6 + nwifeinc +
##     exper + expersq, data = mroz)
##
## Residuals:
##     Min      1Q  Median      3Q     Max
## -3.0827 -0.3160  0.0532  0.3810  2.3551
##
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.3579972  0.3182963  -1.125  0.26135
## educ         0.0998844  0.0150975   6.616 1.13e-10 ***
## age         -0.0035204  0.0054145  -0.650  0.51593
## kidslt6     -0.0558725  0.0886034  -0.631  0.52865
## kidsge6     -0.0176484  0.0278910  -0.633  0.52723
## nwifeinc     0.0056942  0.0033195   1.715  0.08701 .
## exper        0.0407097  0.0133723   3.044  0.00248 **
## expersq     -0.0007473  0.0004018  -1.860  0.06358 .
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.6667 on 420 degrees of freedom
##   (325 observations deleted due to missingness)
## Multiple R-squared:  0.1641, Adjusted R-squared:  0.1502
## F-statistic: 11.78 on 7 and 420 DF,  p-value: 1.023e-13``````
``linearHypothesis(OLSwg, c("age=0", "kidslt6=0", "kidsge6=0", "nwifeinc=0"))``
``````## Linear hypothesis test
##
## Hypothesis:
## age = 0
## kidslt6 = 0
## kidsge6 = 0
## nwifeinc = 0
##
## Model 1: restricted model
## Model 2: lwage ~ educ + age + kidslt6 + kidsge6 + nwifeinc + exper + expersq
##
##   Res.Df    RSS Df Sum of Sq      F Pr(>F)
## 1    424 188.31
## 2    420 186.68  4    1.6254 0.9142 0.4555``````
``summary(IVwg <- ivreg(lwage ~ hours + educ + exper +expersq | age + kidslt6 + kidsge6 + nwifeinc + educ + exper +expersq, data=mroz))``
``````##
## Call:
## ivreg(formula = lwage ~ hours + educ + exper + expersq | age +
##     kidslt6 + kidsge6 + nwifeinc + educ + exper + expersq, data = mroz)
##
## Residuals:
##     Min      1Q  Median      3Q     Max
## -3.6187 -0.3014  0.0242  0.3552  2.4835
##
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.6927900  0.3066002  -2.260   0.0244 *
## hours        0.0001608  0.0002154   0.747   0.4558
## educ         0.1111175  0.0153319   7.247 2.03e-12 ***
## exper        0.0326460  0.0180610   1.808   0.0714 .
## expersq     -0.0006765  0.0004426  -1.528   0.1272
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.685 on 423 degrees of freedom
## Multiple R-Squared: 0.1112,  Adjusted R-squared: 0.1028
## Wald test:  18.8 on 4 and 423 DF,  p-value: 3.084e-14``````

## 9.2 Example 9.6

Nonlinear Labor Supply Function

``````lwagesq <- mroz\$lwage**2
educsq <- mroz\$educ**2
agesq <- mroz\$age**2
nwifeincsq <- mroz\$nwifeinc**2
mroz2 <- cbind(lwagesq, educsq, agesq, nwifeincsq, mroz)

summary(IVls <- ivreg(hours ~ lwage + lwagesq + educ + age + kidslt6 + kidsge6 + nwifeinc | + educ + age + kidslt6 + kidsge6 + nwifeinc + exper + expersq + educsq + agesq + nwifeincsq, data=mroz))``````
``````##
## Call:
## ivreg(formula = hours ~ lwage + lwagesq + educ + age + kidslt6 +
##     kidsge6 + nwifeinc | +educ + age + kidslt6 + kidsge6 + nwifeinc +
##     exper + expersq + educsq + agesq + nwifeincsq, data = mroz)
##
## Residuals:
##      Min       1Q   Median       3Q      Max
## -1938.62  -634.20   -36.94   342.00  9779.72
##
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1657.926    777.276   2.133   0.0335 *
## lwage       1873.620    635.991   2.946   0.0034 **
## lwagesq     -437.291    350.077  -1.249   0.2123
## educ         -87.851     66.393  -1.323   0.1865
## age           -9.142      8.573  -1.066   0.2869
## kidslt6     -185.055    162.281  -1.140   0.2548
## kidsge6      -58.189     50.105  -1.161   0.2462
## nwifeinc      -7.233      5.806  -1.246   0.2135
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1161 on 420 degrees of freedom
## Multiple R-Squared:  -1.2,   Adjusted R-squared: -1.237
## Wald test: 3.543 on 7 and 420 DF,  p-value: 0.001035``````
``````uhat6 <- resid(IVls)
ureg <- lm(uhat6 ~ educ + age + kidslt6 + kidsge6 + nwifeinc + exper + expersq + educsq + agesq + nwifeincsq, data = subset(mroz2, !is.na(lwage)))

``````##
## ========================================
##                  Dependent variable:
##              ---------------------------
##                         uhat6
## ----------------------------------------
## educ                   128.099
##                       (184.034)
## age                    22.794
##                       (87.724)
## kidslt6                 7.451
##                       (156.743)
## kidsge6                -1.183
##                       (50.092)
## nwifeinc                5.765
##                       (14.081)
## exper                  -20.369
##                       (24.307)
## expersq                 0.870
##                        (0.739)
## educsq                 -5.028
##                        (7.113)
## agesq                  -0.323
##                        (1.028)
## nwifeincsq             -0.070
##                        (0.207)
## Constant             -1,172.042
##                      (2,162.256)
## ----------------------------------------
## Observations             428
## R2                      0.006
``````LM <- summary(ureg)\$r.squared * nobs(ureg)
``## [1] 2.612112``
``pchisq(LM, df=3, lower.tail = FALSE)``
``## [1] 0.45537``