<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/missing-data-imputation-and-instrumental-variables-regression-the-tidy-approach/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://www.brodrigues.co/blog/2018-07-01-tidy_ive/"> Econometrics and Free Software</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<div>
<p><a rel="nofollow" href="https://www.youtube.com/watch?v=o5S7CreWiBY/" target="_blank"><br>
<img src="https://i0.wp.com/www.brodrigues.co/blog/2018-07-01-tidy_ive/img/trumpet_boy.jpg?w=450" data-recalc-dims="1"></a></p>
</div>
<p>In this blog post I will discuss missing data imputation and instrumental variables regression. This<br>
is based on a short presentation I will give at my job. You can find the data used here on this<br>
website: <a rel="nofollow" href="http://eclr.humanities.manchester.ac.uk/index.php/IV_in_R" target="_blank">http://eclr.humanities.manchester.ac.uk/index.php/IV_in_R</a></p>
<p>The data is used is from Wooldridge’s book, <em>Econometrics: A modern Approach</em>.<br>
You can download the data by clicking <a rel="nofollow" href="http://eclr.humanities.manchester.ac.uk/images/5/5f/Mroz.csv" target="_blank">here</a>.</p>
<p>This is the variable description:</p>
<pre><code> 1. inlf                     =1 if in labor force, 1975
 2. hours                    hours worked, 1975
 3. kidslt6                  # kids &lt; 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</code></pre>
<p>The goal is to first impute missing data in the data set, and then determine the impact of one added<br>
year of education on wages. If one simply ignores missing values, bias can be introduced depending on<br>
the missingness mechanism. The second problem here is that education is likely to be endogeneous<br>
(and thus be correlated to the error term), as it is not randomly assigned. This causes biased estimates<br>
and may lead to seriously wrong conclusions. So missingness and endogeneity should be dealt with, but<br>
dealing with both issues is more of a programming challenge than an econometrics challenge.<br>
Thankfully, the packages contained in the <code>{tidyverse}</code> as well as <code>{mice}</code> will save the day!</p>
<p>If you inspect the data, you will see that there are no missing values. So I will use the <code>{mice}</code><br>
package to first <em>ampute</em> the data (which means adding missing values). This, of course, is done<br>
for education purposes. If you’re lucky enough to not have missing values in your data, you shouldn’t<br>
add them!</p>
<p>Let’s load all the packages needed:</p>
<pre><code>library(tidyverse)
library(AER)
library(naniar)
library(mice)</code></pre>
<p>So first, let’s read in the data, and ampute it:</p>
<pre><code>wages_data &lt;- read_csv(&quot;http://eclr.humanities.manchester.ac.uk/images/5/5f/Mroz.csv&quot;)</code></pre>
<pre><code>## Parsed with column specification:
## cols(
##   .default = col_integer(),
##   wage = col_character(),
##   repwage = col_double(),
##   huswage = col_double(),
##   mtr = col_double(),
##   unem = col_double(),
##   nwifeinc = col_double(),
##   lwage = col_character()
## )</code></pre>
<pre><code>## See spec(...) for full column specifications.</code></pre>
<p>First, I only select the variables I want to use and convert them to the correct class:</p>
<pre><code>wages_data &lt;- wages_data %>% 
    select(wage, educ, fatheduc, motheduc, inlf, hours, 
               kidslt6, kidsge6, age, huswage, 
               mtr, unem, city, exper) %>% 
    mutate_at(vars(kidslt6, kidsge6, hours, educ, age, wage, huswage, mtr,
                    motheduc, fatheduc, unem, exper), as.numeric) %>% 
    mutate_at(vars(city, inlf), as.character)</code></pre>
<pre><code>## Warning in evalq(as.numeric(wage), </code></pre>