Note
This article is translated from the Mroz 1987: Regression and Instrumental Variables example in the documentation of delicatessen, deli’s Python counterpart.
Mroz explored (mis)specification of statistical models using labor data on married women from 1975. These data were used for a number of examples in the book Econometric Analysis of Cross Section and Panel Data by Jeffrey Wooldridge. Here some of these examples are shown further.
Data
d <- mroz
d <- d[complete.cases(d), ]
d$intercept <- 1Chapter 4: The Single-Equation Linear Model and OLS Estimation
Here, a simple model for the log-transformed wage (lwage) is fit as a function of labor market experience (exper), years of schooling (educ), age (age), number of kids 0-6 years old (kidslt6), and number of kids 6-18 years old (kidsge6). Fitting this model is easily done using the built-in ee_regression functionality.
# Define the design matrix columns
design_cols <- c("intercept", "exper", "expersq", "educ",
"age", "kidslt6", "kidsge6")
# Define estimating equation and estimate
estr <- m_estimate(
stacked_equations = function(theta) {
ee_regression(theta,
X = as.matrix(d[, design_cols]),
y = d$lwage,
model = "linear")
},
init = rep(0, 7)
)
# Results
results <- data.frame(
Param = design_cols,
Coef = estr@theta,
SE = sqrt(diag(estr@variance))
)
results[, -1] <- round(results[, -1], 3)
results
#> Param Coef SE
#> theta_1 intercept -0.421 0.316
#> theta_2 exper 0.040 0.015
#> theta_3 expersq -0.001 0.000
#> theta_4 educ 0.108 0.014
#> theta_5 age -0.001 0.006
#> theta_6 kidslt6 -0.061 0.105
#> theta_7 kidsge6 -0.015 0.029These results match those provided in the box. Note that the reported standard error (SE) here corresponds to the heteroskedasticity-robust standard error reported in the book.
Chapter 5: Instrumental Variables Estimation of Single-Equation Linear Models
The next chapter considers instrumental variable estimation using 2-stage least squares (2SLS). In particular we are interested in the effect of education (educ) on log-transformed wages (lwage). Here, we will account for labor market experience (exper) in both stages. The instruments in this setting are mother’s education (motheduc), father’s education (fatheduc), and husband’s education (huseduc).
We will apply the 2SLS estimator using the built-in ee_2sls function.
# Define estimating equation using built-in 2SLS. The 2SLS estimating
# functions are singular at an all-zero starting value, so we use the
# Levenberg-Marquardt solver ("lm"), which is also the default in Python
# delicatessen.
estr <- m_estimate(
stacked_equations = function(theta) {
ee_2sls(theta,
y = d$lwage,
A = d$educ,
Z = as.matrix(d[, c("motheduc", "fatheduc", "huseduc")]),
W = as.matrix(d[, c("intercept", "exper", "expersq")]))
},
init = rep(0, 1 + 3 + 3 * 2),
solver = "lm"
)
# Results (first 4 parameters are the 2SLS coefficients)
labels_2sls <- c("educ", "intercept", "exper", "expersq")
results <- data.frame(
Param = labels_2sls,
Coef = estr@theta[1:4],
SE = sqrt(diag(estr@variance))[1:4]
)
results[, -1] <- round(results[, -1], 3)
results
#> Param Coef SE
#> stage2_A educ 0.080 0.022
#> stage2_W_1 intercept -0.187 0.300
#> stage2_W_2 exper 0.043 0.015
#> stage2_W_3 expersq -0.001 0.000These results match the output provided in the book. Note that the order of the output of ee_2sls is slightly different from the book.
Example from OneSampleMR
As a final use of the Mroz data, we replicate the example with two action variables (education and labor force experience) from the OneSampleMR documentation, provided here. In this case, we will have age and the number of kids serve as the instruments.
Currently, ee_2sls does not allow for multiple action variables. Therefore, we instead code up the 2SLS estimator using the basic regression functions. Briefly, we fit two models in the first stage (one for educ and one for exper). Using the predicted values from these models, we then fit the second stage model for lwage.
# Instrument design matrix
Z <- as.matrix(d[, c("intercept", "age", "kidslt6", "kidsge6")])
# Define the two-stage estimating equation by hand
estr <- m_estimate(
stacked_equations = function(theta) {
gamma <- theta[1:3]
alpha <- theta[4:7]
beta <- theta[8:11]
# First-stage regression for education
ee_s1a <- ee_regression(alpha, X = Z, y = d$educ,
model = "linear")
a_hat <- as.numeric(Z %*% alpha)
# First-stage regression for experience
ee_s1b <- ee_regression(beta, X = Z, y = d$exper,
model = "linear")
b_hat <- as.numeric(Z %*% beta)
# Second-stage regression for log(wage)
Xhat <- cbind(d$intercept, a_hat, b_hat)
ee_2s <- ee_regression(gamma, X = Xhat, y = d$lwage,
model = "linear")
rbind(ee_2s, ee_s1a, ee_s1b)
},
init = rep(0, 3 + 4 * 2),
solver = "lm"
)
# Results (first 3 parameters are second-stage coefficients)
labels_mr <- c("intercept", "educ", "exper")
results <- data.frame(
Param = labels_mr,
Coef = estr@theta[1:3],
SE = sqrt(diag(estr@variance))[1:3]
)
results[, -1] <- round(results[, -1], 3)
results
#> Param Coef SE
#> theta_1 intercept -0.360 1.105
#> theta_2 educ 0.106 0.088
#> theta_3 exper 0.016 0.008These results mostly match those provided in the documentation. However, note that the SE differs due to the use of a different variance estimator.
References
Mroz, T. A. (1987). The sensitivity of an empirical model of married women’s hours of work to economic and statistical assumptions. Econometrica 55(4), 765-799.
Wooldridge, J. M. (2010). Econometric analysis of cross section and panel data. MIT press.