In this blog post I will discuss missing data imputation and instrumental variables regression. This
is based on a short presentation I will give at my job. You can find the data used here on this
website: http://eclr.humanities.manchester.ac.uk/index.php/IV_in_R
The data is used is from Wooldridge’s book, Econometrics: A modern Approach.
You can download the data by clicking here.
This is the variable description:
1. inlf =1 if in labor force, 1975
2. hours hours worked, 1975
3. kidslt6 # kids __ 6 years
4. kidsge6 # kids 6-18
5. age woman's age in yrs
6. educ years of schooling
7. wage estimated wage from earns., hours
8. repwage reported wage at interview in 1976
9. hushrs hours worked by husband, 1975
10. husage husband's age
11. huseduc husband's years of schooling
12. huswage husband's hourly wage, 1975
13. faminc family income, 1975
14. mtr fed. marginal tax rate facing woman
15. motheduc mother's years of schooling
16. fatheduc father's years of schooling
17. unem unem. rate in county of resid.
18. city =1 if live in SMSA
19. exper actual labor mkt exper
20. nwifeinc (faminc - wage*hours)/1000
21. lwage log(wage)
22. expersq exper^2
The goal is to first impute missing data in the data set, and then determine the impact of one added
year of education on wages. If one simply ignores missing values, bias can be introduced depending on
the missingness mechanism. The second problem here is that education is likely to be endogeneous
(and thus be correlated to the error term), as it is not randomly assigned. This causes biased estimates
and may lead to seriously wrong conclusions. So missingness and endogeneity should be dealt with, but
dealing with both issues is more of a programming challenge than an econometrics challenge.
Thankfully, the packages contained in the {tidyverse} as well as {mice} will save the day!
If you inspect the data, you will see that there are no missing values. So I will use the {mice}
package to first ampute the data (which means adding missing values). This, of course, is done
for education purposes. If you’re lucky enough to not have missing values in your data, you shouldn’t
add them!
Let’s load all the packages needed:
library(tidyverse)
library(AER)
library(naniar)
library(mice)
So first, let’s read in the data, and ampute it:
wages_data % mutate_at(vars(kidslt6, kidsge6, hours, educ, age, wage, huswage, mtr,
motheduc, fatheduc, unem, exper), as.numeric) %__% mutate_at(vars(city, inlf), as.character)
## Warning in evalq(as.numeric(wage), ): NAs introduced by
## coercion
In the data, some women are not in the labour force, and thus do not have any wages; meaning they
should have a 0 there. Instead, this is represented with the following symbol: “.”. So I convert
these dots to 0. One could argue that the wages should not be 0, but that they’re truly missing.
This is true, and there are ways to deal with such questions (Heckman’s selection model for instance),
but this is not the point here.
wages_data % mutate(wage = ifelse(is.na(wage), 0, wage))
Let’s double check if there are any missing values in the data, using naniar::vis_miss():
vis_miss(wages_data)
Nope! Let’s ampute it:
wages_mis