<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="https://www.r-bloggers.com/instrumental-variables-in-r-exercises-part-1/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://www.r-exercises.com/2017/05/15/instrumental-variables-in-r-exercises-part-1/?utm_source=rss&utm_medium=rss&utm_campaign=instrumental-variables-in-r-exercises-part-1"> R-exercises</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p><a target="_blank" rel="nofollow" href="https://i0.wp.com/www.r-exercises.com/wp-content/uploads/2017/05/Rplot_set1.jpeg"><img sizes="(max-width: 150px) 100vw, 150px" alt="" class="wp-image-5754" src="https://i2.wp.com/www.r-exercises.com/wp-content/uploads/2017/05/Rplot_set1-150x150.jpeg?resize=150%2C150" data-recalc-dims="1"></a></p>
<p>One of the most frequently encountered issues in econometrics is endogeneity.<br>
Consider the simple Ordinary Least Squares (OLS) regression setting in which we model wages as a function of years of schooling (education):</p>
<p><a target="_blank" rel="nofollow" href="https://i2.wp.com/www.r-exercises.com/wp-content/uploads/2017/05/eq1.jpg"><img alt="" class="wp-image-5749" src="https://i2.wp.com/www.r-exercises.com/wp-content/uploads/2017/05/eq1.jpg?resize=290%2C21" data-recalc-dims="1"></a><br>
One of the main assumption of OLS is that the independent variables are not correlated with the error term. However, this is seldom the case in most practical applications. The violation of this assumption causes the beta estimates to be biased. In the above example, years of schooling (education) is likely to be correlated with ‘individual ability’ which is part of the error term. Therefore, estimating this model would give a biased estimate of the beta parameter of education as it is considered endogenous. One option is to obtain a measure of ability such as IQ and have it as an independent variable in the model. Availability of such data is not always possible.</p>
<p>A frequently used approach is the method of instrumental variables: intuitively, we need to identify a variable (called instrumental variable) that is not part of the model, has high correlation with the endogenous variable and is uncorrelated with the error term. In our example, one possible candidate for instrumental variable (IV) is father’s education. The appropriateness of the IV is always debatable and it would be a good thought experiment to see why father’s education can fulfill the criteria for an IV we just defined and why it might fail.</p>
<p>The following exercises provide a basic introduction to using instrumental variable technique in R.</p>
<p>Answers to the exercises are available <a target="_blank" rel="nofollow" href="http://r-exercises.com/2017/05/15/instrumental-variables-in-r-exercises-part-1-solutions/">here</a>.</p>
<p><strong>Exercise 1</strong><br>
Load the AER package (package description: <a target="_blank" rel="nofollow" href="https://cran.r-project.org/web/packages/AER/AER.pdf">here</a>). Next, load <code>PSID1976</code> dataset provided with the AER package. This has data regarding labor force participation of married women.<br>
The data is sourced from: Mroz, T. A. (1987) The sensitivity of an empirical model of married women’s hours of work to economic and statistical assumptions. Econometrica 55, 765–799.</p>
<p><strong>Exercise 2</strong><br>
Get summary statistics for the data and identify possible candidates as instrumental variables for education.</p>
<p><strong>Exercise 3</strong><br>
Regress <code>log(wage)</code> on <code>education</code>. Why do you get an error message? (Hint: focus on the <code>participation</code> variable)</p>
<p><strong>Exercise 4</strong><br>
Regress <code>log(wage)</code> on <code>education</code> and state the estimated return to another year of education for women that participated in the labor force. (Hint: use the <code>subset</code> command)</p>
<p>Note: the following exercises are based on the subsample of 428 working women used on exercise-4.</p>
<p><strong>Exercise 5</strong><br>
Plot <code>log(wage)</code> against <code>education</code> along with the fitted regression line from exercise-4.</p>
<p><strong>Exercise 6</strong><br>
Regress <code>education</code> on <code>feducation</code> (father’s years of education) and comment on the estimated correlation.</p>
<p><strong>Exercise 7</strong><br>
The IV estimate of the return to education can be found using the two-stage least squares (2SLS) procedure.<br>
Regress <code>log(wage)</code> on the fitted values of the model estimated in exercise-6.<br>
The beta parameter for the fitted values is the IV estimate for return to education.<br>
Note that the associated standard errors reported are incorrect as these are not based on the usual OLS formula.</p>
<p><strong>Exercise 8</strong><br>
The <code>ivreg</code> function provides a convenient way to estimate IV models and get correct standard errors.<br>
Using the <code>ivreg</code> function, regress <code>log(wage)</code> on education and specify <code>feducation</code> as the IV.<br>
Do you get the same beta estimates as in exercise-6?</p>
<p><strong>Exercise 9</strong><br>
Get 90% confidence intervals for the return to education from exercises 4 and 8.</p>
<p><strong>Exercise 10</strong><br>
Repeat exercises 6 and 8 using mother’s education (<code>meducation</code>) as the IV and comment on the results.</p>
<div>
<h3>Related exercise sets:</h3>
<ol>
<li><a title="Forecasting: ARIMAX Model Exercises (Part-5)" target="_blank" rel="nofollow" href="http://www.r-exercises.com/2017/05/05/forecasting-arimax-model-exercises-part-5/">Forecasting: ARIMAX Model Exercises (Part-5) </a></li>
<li><a title="Model Evaluation Exercises 1" target="_blank" rel="nofollow" href="http://www.r-exercises.com/2016/12/02/model-evaluation-exercise-1/">Model Evaluation Exercises 1 </a></li>
<li><a title="Forecasting: Exponential Smoothing Exercises (Part-3)" target="_blank" rel="nofollow" href="http://www.r-exercises.com/2017/04/17/forecasting-exponential-smoothing-exercises-part-3/">Forecasting: Exponential Smoothing Exercises (Part-3) </a></li>
<li><a target="_blank" rel="nofollow" href="http://www.r-exercises.com/start-here-to-learn-r/">Explore all our (>1000) R exercises</a></li>
<li><a target="_blank" rel="nofollow" href="http://www.r-exercises.com/r-courses/">Find an R course using our R Course Finder</a> directory</li>
</ol>
</div>
<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://www.r-exercises.com/2017/05/15/instrumental-variables-in-r-exercises-part-1/?utm_source=rss&utm_medium=rss&utm_campaign=instrumental-variables-in-r-exercises-part-1"> R-exercises</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a title="The R Project for Statistical Computing" rel="nofollow" href="https://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/search/data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="https://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/search/map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/search/animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/search/sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/search/SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/search/git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/search/hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/search/PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/search/time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/search/trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/hFXdql1riis"></a></div>