background-image: url("../pic/slide-front-page.jpg") class: center,middle count: false # Advanced Econometrics III ## Simultaneous Equation Models (SEM) <!--- chakra: libs/remark-latest.min.js ---> ### Hu Huaping (胡华平 ) ### NWAFU (西北农林科技大学) ### School of Economics and Management (经济管理学院) ### huhuaping01 at hotmail.com ### 2026-06-04
??? Good evening everyone. Welcome to my class. I am teacher Hu Huaping. Here is my email. You can contact me when you have any questions with our course. In this part, we will learn Simultaneous Equation Models together by using almost eight lessons. --- count: false class: center, middle, duke-orange,hide_logo # Simultaneous Equation Models (SEM) .large[ .red[Chapter 17. Endogeneity and Instrumental Variables] Chapter 18. Why Should We Concern SEM ? Chapter 19. What is the Identification Problem ? Chapter 20. How to Estimate SEM ? ] ??? As you see this part contains four chapters. Firstly, we will go through Chapter 17. Regressor Endogeneity problems and instrumental Variables solutions will be discussed in this chapter. Anyway, this chapter will be a good start for learning SEM. The next three chapters focus closely on SEM. We will answer three important questions in turn. In Chapter 18, we will know SEM is important in social science and it also brings new challenges to us. Large SEM system always contains lots of parameters need to be solved and will face with the identification problems. We will give you guides and rules to check the SEM identification status in Chapter 19. Finally, we will discuss different SEM estimation approaches in Chapter 20, including 2SLS, Three-stage least squares (3SLS) and full information maximum likelihood (FIML) method. --- class: center, middle,duke-softblue,hide_logo count: false ## Chapter 17 Endogeneity and IV <br><br><br>(Part B) [Back to Part A](SEM-slide-eng-part0-IV-v3a.html#chapter17a) ??? Part B: identification bridge, 2SLS, and tests. --- layout: false class: center, middle, duke-softblue,hide_logo name: chapter17b # Chapter 17. Endogeneity and Instumental Variables <br> (Part B) [17.6 Two-stage least squares method](#TSLS) [17.7 Testing instrument validity](#validity) [17.8 Testing regressor endogeneity](#endogeneity) [Exercise and Computation](#exercise) ??? [source](https://web.sgh.waw.pl/~mrubas/AdvEcon/pdf/T2_Endogeneity.pdf) So let us start the first chapter. In this chapter: - You will see how the method of **instrumental variables** (IV) can be used to solve the problem of **endogeneity** due to one or more regressors. - Also we will learn the method of **two stage least squares** in section 17.6. 2SLS method is second in popularity only to ordinary least squares for estimating linear equations in econometrics. - And some useful testing techniques will be introduced to check instrument validity and regressor endogeneity. These content will be uncovered in the last two sections. --- layout: false class: center, middle, duke-softblue,hide_logo name: TSLS ## 17.6 Two-stage least squares method ??? In this section, we will discuss how to perform Two-stage least squares estimation procedure. --- layout: true <div class="my-header-h2"></div> <div class="watermark1"></div> <div class="watermark2"></div> <div class="watermark3"></div> <div class="my-footer"><span>huhuaping@ <a href="#chapter17"> Chapter 17. Endogeneity and Instumental Variables |</a>               <a href="#TSLS"> 17.6 Two-stage least squares method </a></span></div> --- ### Recall 17.5: IV as a ratio of two regressions From section 17.5, the IV estimand can be written as `\(\beta^{IV} = \rho / \pi\)` — the ratio of a **reduced-form** coefficient to a **first-stage** coefficient. **2SLS** generalizes this when we have multiple instruments and controls. --- ### Two-stage least squares: glance When we have **more** instruments than endogenous variables, `\(\boldsymbol{\hat{\beta}_{IV}}\)` can be computed in 2 steps: - **Step 1**: Regress each column of `\(X\)` on all the instruments ( `\(Z\)` ,in matrix form ). For each column of `\(X\)`, get the fitted values and combine them into the matrix `\(\hat{X}\)`. - **Step 2**: Regress `\({Y}\)` on `\(\hat{X}\)` And, this procedure is named **two-stage least squares** or **2SLS** or **TSLS**. --- ### Two-stage least squares: indentification Consider the model setting `$$\begin{align} Y_{i}=\beta_{0}+\sum_{j=1}^{k} \beta_{j} X_{j i}+\sum_{s=1}^{r} \beta_{k+s} W_{ri}+\epsilon_{i} \end{align}$$` where `\(\left(X_{1 i}, \ldots, X_{k i}\right)\)` are **endogenous regressors**, `\(\left(W_{1 i}, \ldots, W_{r i}\right)\)` are **exogenous regressors** and there are `\(m\)` **instrumental variables** `\(\left(Z_{1 i}, \ldots, Z_{m i}\right)\)` satisfying instrument relevance and instrument exogeneity conditions. - When `\(m=k\)` ,the coefficients are **exactly identified**. - When `\(m>k\)` ,the coefficients are **overidentified**. - When `\(m<k\)`, the coefficients are **underidentified**. - Finnaly, coefficients can be identified only when `\(m \geq k\)`. ??? Because the model identification is the most important thing before applying the estimation procedure. So, We should overview the model status explicitly. We will denote the general model format as below. --- ### Two-stage least squares: the procedure - **Stage 1**: Regress `\(X_{1i}\)` on constant, all the instruments `\(\left(Z_{1i}, \ldots, Z_{m i}\right)\)` and all exogenous regressors `\(\left(W_{1i}, \ldots, W_{ri}\right)\)` using OLS and obtain the fitted values `\(\hat{X}_{1 i}\)` . Repeat this to get `\(\left(\hat{X}_{1 i}, \ldots, \hat{X}_{k i}\right)\)` - **Stage 2**: Regress `\(Y_{i}\)` on constant, `\(\left(\hat{X}_{1 i}, \ldots, \hat{X}_{k i}\right)\)` and `\(\left(W_{1 i}, \ldots, W_{r i}\right)\)` using OLS to obtain `\(\left(\hat{\beta}_{0}^{IV}, \hat{\beta}_{1}^{IV}, \ldots, \hat{\beta}_{k+r}^{IV}\right)\)` ??? So, in case with “exactly identification” and “over-identification”, we can go ahead with the **Two-Stage Least Squares** as a “whole” solution for IV estimation. --- ### Two-stage least squares: the solutions We can conduct the **2SLS** procedure with following two solutions: - use the **"Step-by-Step solution"** methods without variance correction. - use the **"Integrated solution"** with variance correction. .notes[ **Notice**: DO NOT use **"Step-by-Step solution"** solution in your paper! It is only for teaching purpose here. In `R` ecosystem, we have two packages to execute the **Integrated solution**: - We can use `systemfit` package function `systemfit::systemfit()`. - Or we may use `ARE` package function `ARE::ivreg()`. ] ??? Let us apply these solutions to the empirical wage examples. --- ### Step-by-step solution: stage 1 model First, let's try to use `\(matheduc\)` as instrument of endogenous variable `\(educ\)`. **Stage 1 of 2SLS**: with mother education as instrument we can obtain the fitted variable `\(\widehat{educ}\)` by conduct the following **step 1** OLS regression `$$\begin{align} \widehat{educ} = \hat{\gamma}_1 +\hat{\gamma}_2exper + \hat{\gamma}_3expersq +\hat{\gamma}_4mothereduc \end{align}$$` ??? Again, let us do the demo of two-stage least squares procedure based on the wage example. In the firs stage, we can obtain the fitted variable `\(\widehat{educ}\)` by conduct the following OLS regression. --- ### Step-by-step solution: stage 1 OLS estimate(tidy) Here we obtain the OLS results of **Stage 1 of 2SLS**: ``` r mod_step1 <- formula(educ~exper + expersq + motheduc) # modle setting ols_step1 <- lm(formula = mod_step1, data = mroz) # OLS estimation ``` `$$\begin{equation} \begin{alignedat}{999} &\widehat{educ}=&&+9.78&&+0.05exper_i&&-0.00expersq_i&&+0.27motheduc_i\\ &(s)&&(0.4239)&&(0.0417)&&(0.0012)&&(0.0311)\\ &(t)&&(+23.06)&&(+1.17)&&(-1.03)&&(+8.60)\\ &(fit)&&R^2=0.1527&&\bar{R}^2=0.1467 && &&\\ &(Ftest)&&F^*=25.47&&p=0.0000 && && \end{alignedat} \end{equation}$$` The t -value for coefficient of `\(mothereduc\)` is so large (larger than 2), indicating a strong correlation between this instrument and the endogenous variable `\(educ\)` even after controlling for other variables. ??? we should note that the t-value for coefficient of `\(mothereduc\)` is larger than 2. and the t test is significant. This means there is a strong correlation between the instrument `\(motheduc\)` and the endogenous variable `\(educ\)` even when we control all other variables. --- ### Step-by-step solution: stage 1 OLS estimate(output) Here shows the raw output of stage 1 regression from `R` results: .scroll-box-16[ ``` r summary(ols_step1) ``` ``` Call: lm(formula = mod_step1, data = mroz) Residuals: Min 1Q Median 3Q Max -7.4423 -1.2963 -0.0837 1.1761 5.9870 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 9.775103 0.423889 23.061 <2e-16 *** exper 0.048862 0.041669 1.173 0.242 expersq -0.001281 0.001245 -1.029 0.304 motheduc 0.267691 0.031130 8.599 <2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 2.111 on 424 degrees of freedom Multiple R-squared: 0.1527, Adjusted R-squared: 0.1467 F-statistic: 25.47 on 3 and 424 DF, p-value: 3.617e-15 ``` ] --- ### Step-by-step solution: stage 1 OLS predicted values Along with the regression of **Stage 1 of 2SLS**, we will extract the fitted value `\(\widehat{educ}\)` and add them into new data set. ``` r mroz_add <- mroz %>% # add fitted educ to data set mutate(educHat = fitted(ols_step1)) ```
--- ### Step-by-step solution: stage 2 model **Stage 2 of 2SLS**: with mother education as instrument In the second stage, we will regress log(wage) on the `\(\widehat{educ}\)` from stage 1 and experience and its quadratic term exp square. `$$\begin{align} lwage = \hat{\beta}_1 +\hat{\beta}_2\widehat{educ} + \hat{\beta}_3exper +\hat{\beta}_4expersq + \hat{\epsilon} \end{align}$$` ``` r mod_step2 <- formula(lwage~educHat + exper + expersq) ols_step2 <- lm(formula = mod_step2, data = mroz_add) ``` --- ### Step-by-step solution: stage 2 OLS estimate(tidy) By using the new data set (`moroz_add`), the result of the explicit 2SLS procedure are shown as below. `$$\begin{equation} \begin{alignedat}{999} &\widehat{lwage}=&&+0.20&&+0.05educHat_i&&+0.04exper_i&&-0.00expersq_i\\ &(s)&&(0.4933)&&(0.0391)&&(0.0142)&&(0.0004)\\ &(t)&&(+0.40)&&(+1.26)&&(+3.17)&&(-2.17)\\ &(fit)&&R^2=0.0456&&\bar{R}^2=0.0388 && &&\\ &(Ftest)&&F^*=6.75&&p=0.0002 && && \end{alignedat} \end{equation}$$` .notes[ Keep in mind, however, that the **standard errors** calculated in this way are incorrect (Why?). ] ??? while the t-test on the coefficient of education is not significant because the t statistics is less than the critical value 2. But the model F-test is significant with small p value here. --- ### Step-by-step solution: stage 2 OLS estimate(output) Here shows the raw output of stage 2 regression from `R` results: .scroll-box-16[ ``` r summary(ols_step2) ``` ``` Call: lm(formula = mod_step2, data = mroz_add) Residuals: Min 1Q Median 3Q Max -3.15299 -0.34773 0.02906 0.39023 2.35624 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 0.1981861 0.4933427 0.402 0.68809 educHat 0.0492630 0.0390562 1.261 0.20788 exper 0.0448558 0.0141644 3.167 0.00165 ** expersq -0.0009221 0.0004240 -2.175 0.03019 * --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 0.709 on 424 degrees of freedom Multiple R-squared: 0.04559, Adjusted R-squared: 0.03884 F-statistic: 6.751 on 3 and 424 DF, p-value: 0.0001861 ``` ] --- ### Integrated solution: the whole story We need a **Integrated solution** for following reasons: - We should obtain the correct estimated error for test and inference. - We should avoid tedious steps in the former step-by-step routine. When the model contains more than one endogenous regressors and there are lots available instruments, then the step-by-step solution will get extremely tedious. --- ### Integrated solution: the `R` toolbox In `R` ecosystem, we have two packages to execute the integrated solution: - We can use `systemfit` package function `systemfit::systemfit()`. - Or we may use `ARE` package function `ARE::ivreg()`. Both of these tools can conduct the integrated solution, and will adjust the variance of estimators automatically. --- exclude: true ### Rscript: `ARE::ivreg()` for IV (m) --- ### Integrated solution: `motheduc` IV model In order to get the correct estimated error, we need use the **"integrated solution"** for 2SLS. And we will process the estimation with proper software and tools. Firstly, let's consider using `\(motheduc\)` as the only instrument for `\(educ\)`. `$$\begin{cases} \begin{align} \widehat{educ} &= \hat{\gamma}_1 +\hat{\gamma}_2exper + \hat{\gamma}_3expersq +\hat{\gamma}_4motheduc && \text{(stage 1)}\\ lwage & = \hat{\beta}_1 +\hat{\beta}_2\widehat{educ} + \hat{\beta}_3exper +\hat{\beta}_4expersq + \hat{\epsilon} && \text{(stage 2)} \end{align} \end{cases}$$` --- ### Integrated solution: `motheduc` IV results
- The t-test for variable `educ` is significant (p-value less than 0.05). .footnote[ **Note** : The corresponding code of `R` programming is in the following slides. The table results use the report from the `systemfit::systemfit()` function. ] --- ### (Supplements) R code (m): `systemfit::systemfit()` The R code using `systemfit::systemfit()` as follows: ``` r # load pkg require(systemfit) # set two models eq_1 <- educ ~ exper + expersq + motheduc eq_2 <- lwage ~ educ + exper + expersq sys <- list(eq1 = eq_1, eq2 = eq_2) # specify the instruments instr <- ~ exper + expersq + motheduc # fit models fit.sys <- systemfit( sys, inst=instr, method="2SLS", data = mroz) # summary of model fit smry.system_m <- summary(fit.sys) ``` .footnote[ R script download: [`systemfit-m.R`](scripts/chapter17/chunk-sources/systemfit-m.R) ] --- ### (Supplements) R report (m): `systemfit::systemfit()` The following is the 2SLS analysis report using `systemfit::systemfit() `: .scroll-box-16[ ``` r smry.system_m ``` ``` systemfit results method: 2SLS N DF SSR detRCov OLS-R2 McElroy-R2 system 856 848 2085.49 1.96552 0.150003 0.112323 N DF SSR MSE RMSE R2 Adj R2 eq1 428 424 1889.658 4.456742 2.111100 0.152694 0.146699 eq2 428 424 195.829 0.461861 0.679604 0.123130 0.116926 The covariance matrix of the residuals eq1 eq2 eq1 4.456742 0.304759 eq2 0.304759 0.461861 The correlations of the residuals eq1 eq2 eq1 1.000000 0.212418 eq2 0.212418 1.000000 2SLS estimates for 'eq1' (equation 1) Model Formula: educ ~ exper + expersq + motheduc Instruments: ~exper + expersq + motheduc Estimate Std. Error t value Pr(>|t|) (Intercept) 9.77510269 0.42388862 23.06055 < 2e-16 *** exper 0.04886150 0.04166926 1.17260 0.24161 expersq -0.00128106 0.00124491 -1.02905 0.30404 motheduc 0.26769081 0.03112980 8.59918 < 2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 2.1111 on 424 degrees of freedom Number of observations: 428 Degrees of Freedom: 424 SSR: 1889.658428 MSE: 4.456742 Root MSE: 2.1111 Multiple R-Squared: 0.152694 Adjusted R-Squared: 0.146699 2SLS estimates for 'eq2' (equation 2) Model Formula: lwage ~ educ + exper + expersq Instruments: ~exper + expersq + motheduc Estimate Std. Error t value Pr(>|t|) (Intercept) 0.198186056 0.472877230 0.41911 0.6753503 educ 0.049262953 0.037436026 1.31592 0.1889107 exper 0.044855848 0.013576817 3.30386 0.0010346 ** expersq -0.000922076 0.000406381 -2.26899 0.0237705 * --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 0.679604 on 424 degrees of freedom Number of observations: 428 Degrees of Freedom: 424 SSR: 195.829058 MSE: 0.461861 Root MSE: 0.679604 Multiple R-Squared: 0.12313 Adjusted R-Squared: 0.116926 ``` ] .footnote[ **NOTE** : `systemfit::systemfit()` simultaneously reports the analysis results of two equations in 2SLS! ] --- ### (Supplements) R code (m): `ARE::ivreg()` The R code using `ARE::ivreg()` as follows: .scroll-box-16[ ``` r # load pkg require(AER) # specify model mod_iv_m <- formula(lwage ~ educ + exper + expersq | motheduc + exper + expersq) # fit model lm_iv_m <- ivreg(formula = mod_iv_m, data = mroz) # summary of model fit smry.ivm <- summary(lm_iv_m) ``` ] .footnote[ R script download: [`ivreg-m.R`](scripts/chapter17/chunk-sources/ivreg-m.R) ] --- ### (Supplements) R report (m): `ARE::ivreg()` The following is the 2SLS analysis report using `ARE::ivreg()`: .scroll-box-16[ ``` r smry.ivm ``` ``` Call: AER::ivreg(formula = lwage ~ educ + exper + expersq | motheduc + exper + expersq, data = mroz) Residuals: Min 1Q Median 3Q Max -3.10804 -0.32633 0.06024 0.36772 2.34351 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 0.1981861 0.4728772 0.419 0.67535 educ 0.0492630 0.0374360 1.316 0.18891 exper 0.0448558 0.0135768 3.304 0.00103 ** expersq -0.0009221 0.0004064 -2.269 0.02377 * --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 0.6796 on 424 degrees of freedom Multiple R-Squared: 0.1231, Adjusted R-squared: 0.1169 Wald test: 7.348 on 3 and 424 DF, p-value: 8.228e-05 ``` ] .footnote[ **Note**: `ARE::ivreg()` Only reports the result of the last equation of 2SLS, not include the first equation! ] ??? We can see that the t-test for `\(educ\)` is not significant. We should note that the instruments (motheduc + exper + expersq) are included as whole behind the procedure in this code chunk. But we do not see these instruments in the output. We can see that the t-test on the coefficient of education is still not significant. --- exclude: true ### Rscript: `ARE::ivreg()` for IV (f) --- ### Integrated solution: `fatheduc` IV model Now let's consider using `\(fatheduc\)` as the only instrument for `\(educ\)`. `$$\begin{cases} \begin{align} \widehat{educ} &= \hat{\gamma}_1 +\hat{\gamma}_2exper + \hat{\gamma}_3expersq +\hat{\gamma}_4fatheduc && \text{(stage 1)}\\ lwage & = \hat{\beta}_1 +\hat{\beta}_2\widehat{educ} + \hat{\beta}_3exper +\hat{\beta}_4expersq + \hat{\epsilon} && \text{(stage 2)} \end{align} \end{cases}$$` We will repeat the whole procedure with `R`. ??? We will repeat the whole procedure with `R`. --- ### Integrated solution: `fatheduc` IV results
> The t-test for variable `educ` is significant (p-value less than 0.05). .footnote[ **Note** : The corresponding code of `R` programming is in the following slides. The table results use the report from the `systemfit::systemfit()` function. ] --- ### (Supplements) R code (f): `systemfit::systemfit()` The R code using `systemfit::systemfit()` as follows: ``` r # load pkg require(systemfit) # set two models eq_1 <- educ ~ exper + expersq + fatheduc eq_2 <- lwage ~ educ + exper + expersq sys <- list(eq1 = eq_1, eq2 = eq_2) # specify the instruments instr <- ~ exper + expersq + fatheduc # fit models fit.sys <- systemfit( sys, inst=instr, method="2SLS", data = mroz) # summary of model fit smry.system_f <- summary(fit.sys) ``` .footnote[ R script download: [`systemfit-f.R`](scripts/chapter17/chunk-sources/systemfit-f.R) ] --- ### (Supplements) R report (f): `systemfit::systemfit()` The following is the 2SLS analysis report using `systemfit::systemfit() `: .scroll-box-16[ ``` r smry.system_f ``` ``` systemfit results method: 2SLS N DF SSR detRCov OLS-R2 McElroy-R2 system 856 848 2030.11 1.91943 0.172575 0.134508 N DF SSR MSE RMSE R2 Adj R2 eq1 428 424 1838.719 4.336602 2.082451 0.175535 0.169701 eq2 428 424 191.387 0.451384 0.671851 0.143022 0.136959 The covariance matrix of the residuals eq1 eq2 eq1 4.336602 0.195036 eq2 0.195036 0.451384 The correlations of the residuals eq1 eq2 eq1 1.000000 0.139402 eq2 0.139402 1.000000 2SLS estimates for 'eq1' (equation 1) Model Formula: educ ~ exper + expersq + fatheduc Instruments: ~exper + expersq + fatheduc Estimate Std. Error t value Pr(>|t|) (Intercept) 9.88703429 0.39560779 24.99201 < 2e-16 *** exper 0.04682433 0.04110742 1.13907 0.25532 expersq -0.00115038 0.00122857 -0.93636 0.34962 fatheduc 0.27050610 0.02887859 9.36701 < 2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 2.082451 on 424 degrees of freedom Number of observations: 428 Degrees of Freedom: 424 SSR: 1838.719104 MSE: 4.336602 Root MSE: 2.082451 Multiple R-Squared: 0.175535 Adjusted R-Squared: 0.169701 2SLS estimates for 'eq2' (equation 2) Model Formula: lwage ~ educ + exper + expersq Instruments: ~exper + expersq + fatheduc Estimate Std. Error t value Pr(>|t|) (Intercept) -0.061116933 0.436446128 -0.14003 0.8887003 educ 0.070226291 0.034442694 2.03893 0.0420766 * exper 0.043671588 0.013400121 3.25904 0.0012079 ** expersq -0.000882155 0.000400917 -2.20034 0.0283212 * --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 0.671851 on 424 degrees of freedom Number of observations: 428 Degrees of Freedom: 424 SSR: 191.386653 MSE: 0.451384 Root MSE: 0.671851 Multiple R-Squared: 0.143022 Adjusted R-Squared: 0.136959 ``` ] .footnote[ **NOTE** : `systemfit::systemfit()` simultaneously reports the analysis results of two equations in 2SLS! ] --- ### (Supplements) R code (f): `ARE::ivreg()` The R code using `ARE::ivreg()` as follows: .scroll-box-16[ ``` r require(AER) mod_iv_f <- formula(lwage ~ educ + exper + expersq | fatheduc + exper + expersq) lm_iv_f <- ivreg(formula = mod_iv_f, data = mroz) smry.ivf <- summary(lm_iv_f) ``` .footnote[ R script download: [`ivreg-f.R`](scripts/chapter17/chunk-sources/ivreg-f.R) ] ] ??? We can see the insturments (fatheduc + exper + expersq) are included as whole behind the procedure in this code chunk. While, We can find that the t-test on the coefficient of education is significant now with its p value less than 0.05. --- ### (Supplements) R report (f): `ARE::ivreg()` The following is the 2SLS analysis report using `ARE::ivreg()`: .scroll-box-16[ ``` r smry.ivf ``` ``` Call: AER::ivreg(formula = lwage ~ educ + exper + expersq | fatheduc + exper + expersq, data = mroz) Residuals: Min 1Q Median 3Q Max -3.09170 -0.32776 0.05006 0.37365 2.35346 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) -0.0611169 0.4364461 -0.140 0.88870 educ 0.0702263 0.0344427 2.039 0.04208 * exper 0.0436716 0.0134001 3.259 0.00121 ** expersq -0.0008822 0.0004009 -2.200 0.02832 * --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 0.6719 on 424 degrees of freedom Multiple R-Squared: 0.143, Adjusted R-squared: 0.137 Wald test: 8.314 on 3 and 424 DF, p-value: 2.201e-05 ``` ] .footnote[ **Note**: `ARE::ivreg()` Only reports the result of the last equation of 2SLS, not include the first equation! ] --- exclude: true ### Rscript: `ARE::ivreg()` for IV (mf) --- ### Integrated solution: `mothedu` and `fatheduc` IV model Also, we can use both `\(motheduc\)` and `\(fatheduc\)` as instruments for `\(educ\)`. `$$\begin{cases} \begin{align} \widehat{educ} &= \hat{\gamma}_1 +\hat{\gamma}_2exper + \hat{\beta}_3expersq +\hat{\beta}_4motheduc + \hat{\beta}_5fatheduc && \text{(stage 1)}\\ lwage & = \hat{\beta}_1 +\hat{\beta}_2\widehat{educ} + \hat{\beta}_3exper +\hat{\beta}_4expersq + \hat{\epsilon} && \text{(stage 2)} \end{align} \end{cases}$$` --- ### Integrated solution: `mothedu` and `fatheduc` IV results
.footnote[ **Note** : The corresponding code of `R` programming is in the following slides. The table results use the report from the `systemfit::systemfit()` function. ] ??? We can see that the t-test result of the coefficient of variable `educ` is significant (p-value less than 0.1). The insturments (motheduc +fatheduc + exper + expersq) are included behind the procedure in this code chunk. And we can find that the t-test on the coefficient of education is significant with its p value less than 0.1. --- ### (Supplements) R code (mf): `systemfit::systemfit()` The R code using `systemfit::systemfit()` as follows: ``` r # load pkg require(systemfit) # set two models eq_1 <- educ ~ exper + expersq + motheduc + fatheduc eq_2 <- lwage ~ educ + exper + expersq sys <- list(eq1 = eq_1, eq2 = eq_2) # specify the instruments instr <- ~ exper + expersq + motheduc + fatheduc # fit models fit.sys <- systemfit( sys, inst=instr, method="2SLS", data = mroz) # summary of model fit smry.system_mf <- summary(fit.sys) ``` .footnote[ R script download: [`systemfit-mf.R`](scripts/chapter17/chunk-sources/systemfit-mf.R) ] --- ### (Supplements) R report (mf): `systemfit::systemfit()` The following is the 2SLS analysis report using `systemfit::systemfit() `: .scroll-box-16[ ``` r smry.system_mf ``` ``` systemfit results method: 2SLS N DF SSR detRCov OLS-R2 McElroy-R2 system 856 847 1951.6 1.83425 0.204575 0.149485 N DF SSR MSE RMSE R2 Adj R2 eq1 428 423 1758.58 4.157388 2.038967 0.211471 0.204014 eq2 428 424 193.02 0.455236 0.674712 0.135708 0.129593 The covariance matrix of the residuals eq1 eq2 eq1 4.157388 0.241536 eq2 0.241536 0.455236 The correlations of the residuals eq1 eq2 eq1 1.000000 0.175571 eq2 0.175571 1.000000 2SLS estimates for 'eq1' (equation 1) Model Formula: educ ~ exper + expersq + motheduc + fatheduc Instruments: ~exper + expersq + motheduc + fatheduc Estimate Std. Error t value Pr(>|t|) (Intercept) 9.10264011 0.42656137 21.33958 < 2.22e-16 *** exper 0.04522542 0.04025071 1.12359 0.26182 expersq -0.00100909 0.00120334 -0.83857 0.40218 motheduc 0.15759703 0.03589412 4.39061 1.4298e-05 *** fatheduc 0.18954841 0.03375647 5.61517 3.5615e-08 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 2.038967 on 423 degrees of freedom Number of observations: 428 Degrees of Freedom: 423 SSR: 1758.575263 MSE: 4.157388 Root MSE: 2.038967 Multiple R-Squared: 0.211471 Adjusted R-Squared: 0.204014 2SLS estimates for 'eq2' (equation 2) Model Formula: lwage ~ educ + exper + expersq Instruments: ~exper + expersq + motheduc + fatheduc Estimate Std. Error t value Pr(>|t|) (Intercept) 0.048100307 0.400328078 0.12015 0.9044195 educ 0.061396629 0.031436696 1.95302 0.0514742 . exper 0.044170393 0.013432476 3.28833 0.0010918 ** expersq -0.000898970 0.000401686 -2.23799 0.0257400 * --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 0.674712 on 424 degrees of freedom Number of observations: 428 Degrees of Freedom: 424 SSR: 193.020015 MSE: 0.455236 Root MSE: 0.674712 Multiple R-Squared: 0.135708 Adjusted R-Squared: 0.129593 ``` ] .footnote[ **NOTE** : `systemfit::systemfit()` simultaneously reports the analysis results of two equations in 2SLS! ] --- ### (Supplements) R code (mf): `ARE::ivreg()` The R code using `ARE::ivreg()` as follows: .scroll-box-16[ ``` r # load pkg require(AER) # specify model mod_iv_mf <- formula( lwage ~ educ + exper + expersq | motheduc + fatheduc + exper + expersq) # fit model lm_iv_mf <- ivreg(formula = mod_iv_mf, data = mroz) # summary of model fit smry.ivmf <- summary(lm_iv_mf) ``` ] .footnote[ R script download: [`ivreg-mf.R`](scripts/chapter17/chunk-sources/ivreg-mf.R) ] --- ### (Supplements) R report (mf): `ARE::ivreg()` The following is the 2SLS analysis report using `ARE::ivreg()`: .scroll-box-16[ ``` r smry.ivmf ``` ``` Call: AER::ivreg(formula = lwage ~ educ + exper + expersq | motheduc + fatheduc + exper + expersq, data = mroz) Residuals: Min 1Q Median 3Q Max -3.0986 -0.3196 0.0551 0.3689 2.3493 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 0.0481003 0.4003281 0.120 0.90442 educ 0.0613966 0.0314367 1.953 0.05147 . exper 0.0441704 0.0134325 3.288 0.00109 ** expersq -0.0008990 0.0004017 -2.238 0.02574 * --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 0.6747 on 424 degrees of freedom Multiple R-Squared: 0.1357, Adjusted R-squared: 0.1296 Wald test: 8.141 on 3 and 424 DF, p-value: 2.787e-05 ``` ] .footnote[ **Note**: `ARE::ivreg()` Only reports the result of the last equation of 2SLS, not include the first equation! ] --- ### Solutions comparison: a glance Until now, we obtain totally **Five** estimation results with different model settings or solutions: a. Error specification model with OLS regression directly. b. (**Step-by-Step solution**) Explicit 2SLS estimation **without** variance correction (IV regression step by step with only `\(matheduc\)` as instrument). c. (**Integrated solution**) Dedicated IV estimation **with** variance correction ( using `R` tools of `systemfit::systemfit()` or `ARE::ivreg()`). - The IV model with only `\(motheduc\)` as instrument for endogenous variable `\(edu\)` - The IV model with only `\(fatheduc\)` as instrument for endogenous variable `\(edu\)` - The IV model with both `\(motheduc\)` and `\(fatheduc\)` as instruments For the purpose of comparison, all results will show in next slide. ??? we use `R` function `ARE::ivreg()` to get the IV estimation **with** variance correction with the last three model considering different instruments. --- ### Solutions comparison: tidy reports (png) <img src="../pic/chpt17-iv-comparison.png" width="946" /> --- ### Solutions comparison: tidy reports (html) .scroll-output[ .tbl-fontsize[ <table style="text-align:center"><tr><td colspan="6" style="border-bottom: 1px solid black"></td></tr><tr><td style="text-align:left"></td><td colspan="5">Dependent variable: lwage</td></tr> <tr><td></td><td colspan="5" style="border-bottom: 1px solid black"></td></tr> <tr><td style="text-align:left"></td><td>OLS</td><td>explicit 2SLS</td><td>IV mothereduc</td><td>IV fathereduc</td><td>IV mothereduc and fathereduc</td></tr> <tr><td style="text-align:left"></td><td>(1)</td><td>(2)</td><td>(3)</td><td>(4)</td><td>(5)</td></tr> <tr><td colspan="6" style="border-bottom: 1px solid black"></td></tr><tr><td style="text-align:left">Constant</td><td>-0.5220<sup>***</sup></td><td>0.1982</td><td>0.1982</td><td>-0.0611</td><td>0.0481</td></tr> <tr><td style="text-align:left"></td><td>(0.1986)</td><td>(0.4933)</td><td>(0.4729)</td><td>(0.4364)</td><td>(0.4003)</td></tr> <tr><td style="text-align:left"></td><td></td><td></td><td></td><td></td><td></td></tr> <tr><td style="text-align:left">educ</td><td>0.1075<sup>***</sup></td><td></td><td>0.0493</td><td>0.0702<sup>**</sup></td><td>0.0614<sup>*</sup></td></tr> <tr><td style="text-align:left"></td><td>(0.0141)</td><td></td><td>(0.0374)</td><td>(0.0344)</td><td>(0.0314)</td></tr> <tr><td style="text-align:left"></td><td></td><td></td><td></td><td></td><td></td></tr> <tr><td style="text-align:left">educHat</td><td></td><td>0.0493</td><td></td><td></td><td></td></tr> <tr><td style="text-align:left"></td><td></td><td>(0.0391)</td><td></td><td></td><td></td></tr> <tr><td style="text-align:left"></td><td></td><td></td><td></td><td></td><td></td></tr> <tr><td style="text-align:left">exper</td><td>0.0416<sup>***</sup></td><td>0.0449<sup>***</sup></td><td>0.0449<sup>***</sup></td><td>0.0437<sup>***</sup></td><td>0.0442<sup>***</sup></td></tr> <tr><td style="text-align:left"></td><td>(0.0132)</td><td>(0.0142)</td><td>(0.0136)</td><td>(0.0134)</td><td>(0.0134)</td></tr> <tr><td style="text-align:left"></td><td></td><td></td><td></td><td></td><td></td></tr> <tr><td style="text-align:left">expersq</td><td>-0.0008<sup>**</sup></td><td>-0.0009<sup>**</sup></td><td>-0.0009<sup>**</sup></td><td>-0.0009<sup>**</sup></td><td>-0.0009<sup>**</sup></td></tr> <tr><td style="text-align:left"></td><td>(0.0004)</td><td>(0.0004)</td><td>(0.0004)</td><td>(0.0004)</td><td>(0.0004)</td></tr> <tr><td style="text-align:left"></td><td></td><td></td><td></td><td></td><td></td></tr> <tr><td colspan="6" style="border-bottom: 1px solid black"></td></tr><tr><td style="text-align:left">Observations</td><td>428</td><td>428</td><td>428</td><td>428</td><td>428</td></tr> <tr><td style="text-align:left">R<sup>2</sup></td><td>0.1568</td><td>0.0456</td><td>0.1231</td><td>0.1430</td><td>0.1357</td></tr> <tr><td style="text-align:left">Adjusted R<sup>2</sup></td><td>0.1509</td><td>0.0388</td><td>0.1169</td><td>0.1370</td><td>0.1296</td></tr> <tr><td style="text-align:left">Residual Std. Error (df = 424)</td><td>0.6664</td><td>0.7090</td><td>0.6796</td><td>0.6719</td><td>0.6747</td></tr> <tr><td style="text-align:left">F Statistic (df = 3; 424)</td><td>26.2862<sup>***</sup></td><td>6.7510<sup>***</sup></td><td></td><td></td><td></td></tr> <tr><td colspan="6" style="border-bottom: 1px solid black"></td></tr></table> ] ] .footnote[ Table source: [`comparison-stargazer.R`](scripts/chapter17/chunk-sources/comparison-stargazer.R) (run in a clean R session; slides use cached HTML). ] ??? 参看在线图书"Principles of Econometrics with R"(10.1 The Instrumental Variables (IV) Method,[免费在线](https://bookdown.org/ccolonescu/RPoE4/random-regressors.html#the-instrumental-variables-iv-method)) --- ### Solutions comparison: report tips - The second column shows the result of the direct OLS estimation, and the third column shows the result of explicit 2SLS estimation without variance correction. - While the last three column shows the results of IV solution with variance correction. - And we should also remind that the `\(educ\)` in the IV model is equivalent to the `\(educHat\)` in 2SLS. - The value within the bracket is the standard error of the estimator. --- ### Solutions comparison: report insights So the key points of this comparison including: - Firstly, the table shows that the importance of education in determining wage decreases in the IV model (3) (4) and (5) with the coefficients 0.049, 0.07, 0.061 respectively. And the standard error also decrease along IV estimation (3) , (4) and (5). - Secondly, It also shows that the explicit 2SLS model (2) and the IV model with only `\(motheduc\)` instrument yield the same coefficients, but the **standard errors** are different. The standard error in explicit 2SLS is 0.039, which is little large than the standard error 0.037 in IV estimation. - Thirdly, the t-test of the coefficient on education shows no significance when we use `motheduc` as the only instrument for education. You can compare this under the explicit 2SLS estimation or IV estimation. - Fourthly, we can fully feel and understand the **relative estimated efficiency** of 2SLS! --- ### Solutions comparison: further thinking After the empirical comparison, we will be even more confused with these results. While, new question will arise inside our mind. - Which estimation is the best? - How to judge and evaluate different instrument choices? We will discuss these topics in the next section. --- layout: false class: center, middle, duke-softblue,hide_logo name: validity ## 17.7 Testing Instrument validity ??? As we know, valid instruments should satisfy both relevance condition and exogeneity condition. So, let us check these conditions in this section. --- layout: true <div class="my-header-h2"></div> <div class="watermark1"></div> <div class="watermark2"></div> <div class="watermark3"></div> <div class="my-footer"><span>huhuaping@ <a href="#chapter17"> Chapter 17. Endogeneity and Instumental Variables |</a>               <a href="#validity"> 17.7 Testing Instrument validity </a></span></div> --- ### Instrument vality: the concept Consider the general model `$$\begin{align} Y_{i}=\beta_{0}+\sum_{j=1}^{k} \beta_{j} X_{j i}+\sum_{s=1}^{r} \beta_{k+s} W_{ri}+\epsilon_{i} \end{align}$$` > - `\(Y_{i}\)` is the dependent variable - `\(\beta_{0}, \ldots, \beta_{k+1}\)` are `\(1+k+r\)` unknown regression coefficients - `\(X_{1 i}, \ldots, X_{k i}\)` are `\(k\)` endogenous regressors - `\(W_{1 i}, \ldots, W_{r i}\)` are `\(r\)` exogenous regressors which are uncorrelated with `\(u_{i}\)` - `\(u_{i}\)` is the error term - `\(Z_{1 i}, \ldots, Z_{m i}\)` are `\(m\)` instrumental variables **Instrument valid** means satisfy both Relevance and Exogeneity conditions. .pull-left[ `$$E\left(Z_{i} X_{i}^{\prime}\right) \neq 0$$` ] .pull-right[ `$$E\left(Z_{i} \epsilon_{i}\right)=0$$` ] ??? Consider the general model as we have done. --- ### Instrument Relevance: relax condition In practice, **Instrument Relevance** also means that: If there are `\(k\)` endogenous variables and `\(m\)` instruments `\(Z\)`, and `\(m \geq k\)`, it must hold that the exogenous vector `$$\left(\hat{X}_{1 i}^{*}, \ldots, \hat{X}_{k i}^{*}, W_{1 i}, \ldots, W_{r i}, 1\right)$$` should .red[not] be **perfectly multicollinear**. > **Where**: > - `\(\hat{X}_{1i}^{\ast}, \ldots, \hat{X}_{ki}^{\ast}\)` are the predicted values from the `\(k\)` first stage regressions. > - 1 denotes the constant regressor which equals 1 for all observations. ??? While the concept of **Instrument Relevance** is much tricky. So, what is the meaning of **Instrument Relevance**? ___ Obviously, the perfect multicollinear is the rare fact and can be get rid with careful inspection. What we really need to pay attention is the contrary fact which is called **weak instruments**. --- ### Instrument Relevance: Weak instrument Instruments that explain little variation in the endogenous regressor `\(X\)` are called **weak instruments**. Formally, When `\(\operatorname{corr}\left(Z_{i}, X_{i}\right)\)` is close to zero, `\(z_{i}\)` is called a weak instrument. - Consider a simple one regressor model `\(Y_{i}=\beta_{0}+\beta_{1} X_{i}+\epsilon_{i}\)` - The IV estimator of `\(\beta_{1}\)` is `\(\widehat{\beta}_{1}^{IV}=\frac{\sum_{i=1}^{n}\left(Z_{i}-\bar{Z}\right)\left(Y_{i}-\bar{Y}\right)}{\sum_{i=1}^{n}\left(Z_{i}-\bar{Z}\right)\left(X_{i}-\bar{X}\right)}\)` > Note that `\(\frac{1}{n} \sum_{i=1}^{n}\left(Z_{i}-\bar{Z}\right)\left(Y_{i}-\bar{Y}\right) \xrightarrow{p} \operatorname{Cov}\left(Z_{i}, Y_{i}\right)\)` > and `\(\frac{1}{n} \sum_{i=1}^{n}\left(Z_{i}-\bar{Z}\right)\left(X_{i}-\bar{X}\right) \xrightarrow{p} \operatorname{Cov}\left(Z_{i}, X_{i}\right)\)`. - Thus,if `\(\operatorname{Cov}\left(Z_{i},X_{i}\right) \approx 0\)`, then `\(\widehat{\beta}_{1}^{IV}\)` is useless. ??? Let me give you an example. --- ### Example: Weak instrument We focus on the effect of cigarette smoking on the infant birth weight. Without other explanatory variables, the model is - `\(bwght =\)` child birth weight, in ounces. - `\(packs =\)` packs smoked per day while pregnant. - `\(cigprice=\)` cigarette price in home state `$$\begin{align} \log (\text {bwght})=\beta_{0}+\beta_{1} \text {packs}+u_{i} \end{align}$$` - We might worry that packs is cor-related with other health factors or the availability of good prenatal care, so that `\(packs\)` and `\(u_i\)` might be correlated. - A possible instrumental variable for `\(packs\)` is the average price of cigarettes ( `\(cigprice\)`) in the state . We will assume that `\(cigprice\)` and `\(u_i\)` are uncorrelated. .footnote[ We will use data set from `wooldridge::bwght`. ] ??? the assumed TRUE model may be `$$\begin{align} \log (\text {bwght})=\beta_{0}+\beta_{1} \text {packs}+ ( \beta_2 care\_surport)+u_{i} \end{align}$$` - `\(cigs =\)` number of cigarettes smoked by the mother while pregnant, per day. - `\(faminc=\)` annual family income, in thousands of dollars. --- ### Example: Weak instrument However, by regressing `\(packs\)` on `\(cigprice\)` in stage 1, we find basically no effect. `$$\begin{equation} \begin{alignedat}{999} &\widehat{packs}=&&+0.0674&&+0.0003cigprice_i\\ &(s)&&(0.1025)&&(0.0008)\\ &(t)&&(+0.66)&&(+0.36)\\ &(Ftest)&&F^*=0.13&&p=0.7179 \end{alignedat} \end{equation}$$` If we insist to use `\(cigprice\)` as instrument, and run the stage 2 OLS, we will find `$$\begin{equation} \begin{alignedat}{999} &\widehat{lbwght}=&&+4.4481&&+2.9887packs\_hat_i\\ &(s)&&(0.1843)&&(1.7654)\\ &(t)&&(+24.13)&&(+1.69)\\ &(Ftest)&&F^*=2.87&&p=0.0907 \end{alignedat} \end{equation}$$` .footnote[ Obviously, this estimation is meaningless (Why?).The `\(cigprice\)` behaves as a **weak instrument**, and the problem was already exposed in stage 1 regression. ] ??? `$$\begin{alignedat}{3} \widehat{packs} &&= && 0.067 + &&0.0003 \text { cigprice } \\ (se)&& &&(0.103) &&(0.0008) \end{alignedat}$$` `$$\begin{alignedat}{3} \log \widehat{(bwght)} &= & 4.45 + &2.99 \text {packs} \\ (se)& &(0.91) &(8.70)\\ \end{alignedat}$$` - because there is huge standard error and not significant on coefficient of packs. - and also it has the wrong sign on coefficient of packs, which should not be positive. As what we have discussed, the result is unbelievable since the cigprice is a weak instrument for packs. --- ### Weak instrument: the strategy The weak instrument ( `\(Z_i\)` and `\(X_i\)` is week correlated) led to an **important finding**: even with very large sample sizes the 2SLS estimator can be biased and a distribution that is very different from standard normal (Staiger and Stock 1997). There are two ways to proceed if instruments are weak: - Discard the **weak instruments** and/or find **stronger instruments**. > While the former is only an option if the unknown coefficients remain identified when the weak instruments are discarded, the latter can be difficult and even may require a redesign of the whole study. - Stick with the weak instruments but use methods that improve upon TSLS. > Such as **limited information maximum likelihood estimation (LIML)**. ??? So, what should we do if the instruments are weak or some of them are weak? --- ### Weak IV: Angrist and Kolesár (2022) .fyi[ **Classic guidance**: if the first-stage **F-statistic** `\(< 10\)` (Staiger and Stock 1997), treat instruments as **weak** — 2SLS can be biased toward OLS with inflated inference problems. ] Angrist and Kolesár (2022) argue that in many applied settings the **standard-error inflation** is large enough that spurious rejection of `\(\beta = 0\)` remains unlikely. - Still report first-stage F and inspect first-stage coefficients. .footnote[ Angrist, J., and M. Kolesár. One Instrument to Rule Them All: The Bias and Coverage of Just-ID IV[J]. Journal of Econometrics, 2022, 240(2):105398. ] --- ### Many instruments and many-weak bias With **many** instruments, first-stage F can look adequate while 2SLS still drifts toward OLS (**many-weak bias**). - Flexible first stages fit `\(D_i\)` better `\(\rightarrow\)` smaller SEs but risk **overfitting** endogenous variation. - Famous example: Angrist–Krueger (1991) QOB instruments with many interactions. - **Practical rule**: prefer **few, strong** instruments; check F after every specification change; beware constructed instruments (judge IV, shift-share, etc.). --- ### Weak instrument: restricted F-test (idea) In case with a **single** endogenous regressor, we can take the **F-test** to check the **Weak instrument**. .notes[ The basic idea of the F-test is very simple: If the estimated coefficients of **all instruments** in the **first-stage** of a 2SLS estimation are **zero**, the instruments do not explain any of the variation in the `\(X\)` which clearly violates the relevance assumption. ] --- ### Weak instrument: restricted F-test (procudure) We may use the following rule of thumb: - Conduct the **first-stage regression** of a 2SLS estimation `$$\begin{align} X_{i}=\hat{\gamma}_{0}+\hat{\gamma}_{1} W_{1 i}+\ldots+\hat{\gamma}_{p} W_{p i}+ \hat{\theta}_{1} Z_{1 i}+\ldots+\hat{\theta}_{q} Z_{q i}+v_{i} \quad \text{(3)} \end{align}$$` - Test the restricted joint hypothesis `\(H_0: \hat{\theta}_1=\ldots=\hat{\theta}_q=0\)` by compute the `\(F\)`-statistic. We call this **Restricted F-test** which is different with the **Classical overall F-test**. - If the `\(F\)`-statistic is less than critical value, the instruments are **weak**. .fiy[ The rule of thumb is easily implemented in `R`. Run the first-stage regression using `lm()` and subsequently compute the restricted `\(F\)`-statistic by `R` function of `car::linearHypothesis()`. ] .footnote[ The Classical overall F-test has `\(H_0:\gamma_1 = \cdots = \gamma_p =\hat{\theta}_1=\ldots=\hat{\theta}_q=0\)` ] ??? Also, you may ask that how do you know the instruments are weak or some of them are weak? We will test this considering with different situations. --- ### Wage example: restricted F-test (models) For all three IV model, we can test instrument(s) relevance respectively. `$$\begin{align} educ &= \gamma_1 +\gamma_2exper +\gamma_2expersq + \theta_1motheduc +v && \text{(relevance test 1)}\\ educ &= \gamma_1 +\gamma_2exper +\gamma_2expersq + \theta_2fatheduc +v && \text{(relevance test 2)} \\ educ &= \gamma_1 +\gamma_2exper +\gamma_2expersq + \theta_1motheduc + \theta_2fatheduc +v && \text{(relevance test 3)} \end{align}$$` ??? And we will test the weak instrument issues by using restricted F test. --- ### Wage example: restricted F-test (model 1) Consider model 1: `$$\begin{align} educ &= \gamma_1 +\gamma_2exper +\gamma_3expersq + \theta_1motheduc +v \end{align}$$` The restricted F-test' null hypothesis: `\(H_0: \theta_1 =0\)`. We will test whether `motheduc` are week instruments. --- ### Wage example: restricted F-test (model 1) The result show that the p-value of `\(F^{\ast}\)` is much smaller than 0.01. Null hypothesis `\(H_0\)` was rejected. `motheduc` is **instruments relevance** (exogeneity valid). .panelset[ .panel[.panel-name[R Code] ``` r # restricted F-test constrain_test1 <- linearHypothesis(model =ols_relevance1, c("motheduc=0")) # obtain F statistics F_r1 <- constrain_test1$F[[2]] ``` ] .panel[.panel-name[R result] ``` Linear hypothesis test: motheduc = 0 Model 1: restricted model Model 2: educ ~ exper + expersq + motheduc Res.Df RSS Df Sum of Sq F Pr(>F) 1 425 2219.2 2 424 1889.7 1 329.56 73.946 < 2.2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 ``` ] ] --- ### Wage example (compare): classic F-test (model 1) > Note: **Restriced F test** (73.95) is different with the **classical OLS F test**(show bellow 25.47). `$$\begin{align} educ &= \gamma_1 +\gamma_2exper +\gamma_2expersq + \theta_1motheduc +v \end{align}$$` The classic OLS F-test' null hypothesis: `\(H_0: \gamma_2 = \gamma_3= \theta_1 =0\)`. The OLS estimation results are: `$$\begin{equation} \begin{alignedat}{999} &\widehat{educ}=&&+9.78&&+0.05exper_i&&-0.00expersq_i&&+0.27motheduc_i\\ &(s)&&(0.4239)&&(0.0417)&&(0.0012)&&(0.0311)\\ &(t)&&(+23.06)&&(+1.17)&&(-1.03)&&(+8.60)\\ &(fit)&&R^2=0.1527&&\bar{R}^2=0.1467 && &&\\ &(Ftest)&&F^*=25.47&&p=0.0000 && && \end{alignedat} \end{equation}$$` ??? Restricted F test take the Null hypotheis with coefficients before the instruments all euqal to zero, While the classical F test take the Null hypotheis with coefficients before all regressors equal to zero. --- ### Wage example: restricted F-test (model 2) Consider model 2: `$$\begin{align} educ &= \gamma_1 +\gamma_2exper +\gamma_3expersq + \theta_1fatheduc +v && \text{(relevance test 2)} \end{align}$$` The restricted F-test' null hypothesis: `\(H_0: \theta_1 =0\)`. We will test whether `fatheduc` are week instruments. --- ### Wage example: restricted F-test (model 2) The result show that the p-value of `\(F^{\ast}\)` is much smaller than 0.01. Null hypothesis `\(H_0\)` was rejected. `fatheduc` is **instruments relevance** (exogeneity valid). .panelset[ .panel[.panel-name[R Code] ``` r constrain_test2 <- linearHypothesis(ols_relevance2, c("fatheduc=0")) # obtain F statistics F_r2 <- constrain_test2$F[[2]] ``` ] .panel[.panel-name[R result] ``` Linear hypothesis test: fatheduc = 0 Model 1: restricted model Model 2: educ ~ exper + expersq + fatheduc Res.Df RSS Df Sum of Sq F Pr(>F) 1 425 2219.2 2 424 1838.7 1 380.5 87.741 < 2.2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 ``` ] ] --- ### Wage example: restricted F-test (model 3) Consider model 3: `$$\begin{align} educ &= \gamma_1 +\gamma_2exper +\gamma_3expersq + \theta_1motheduc + \theta_2fatheduc +v && \text{(relevance test 3)} \end{align}$$` The restricted F-test' null hypothesis: `\(H_0: \theta_1 = \theta_2 =0\)`. We will test whether `motheduc` and `fatheduc` are week instruments. --- ### Wage example: restricted F-test (model 3) The result show that the p-value of `\(F^{\ast}\)` is much smaller than 0.01. Null hypothesis `\(H_0\)` was rejected. `fatheduc` and `motheduc` are **instruments relevance** (exogeneity valid). .panelset[ .panel[.panel-name[R Code] ``` r constrain_test3 <- linearHypothesis(ols_relevance3, c("motheduc=0", "fatheduc=0")) # obtain F statistics F_r3 <- constrain_test3$F[[2]] ``` ] .panel[.panel-name[R result] ``` Linear hypothesis test: motheduc = 0 fatheduc = 0 Model 1: restricted model Model 2: educ ~ exper + expersq + motheduc + fatheduc Res.Df RSS Df Sum of Sq F Pr(>F) 1 425 2219.2 2 423 1758.6 2 460.64 55.4 < 2.2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 ``` ] ] ??? In sum, all relecance model test are significant. And we can conclude that the instrumenta mothereducation and father education satisify the relevance condition. Until now, we show the relevance F-test with situation that contains only one endogenous regressor. Next, I will give a two endogeous variables example by using Cragg-Donald test. --- ### Weak instrument: Cragg-Donald test The former test for weak instruments might be unreliable with **more than** one endogenous regressor, though, because there is indeed one `\(F\)`-statistic for each endogenous regressor. An alternative is the **Cragg-Donald test** based on the following statistic: `$$\begin{align} F=\frac{N-G-B}{L} \frac{r_{B}^{2}}{1-r_{B}^{2}} \end{align}$$` - where: `\(G\)` is the number of exogenous regressors; `\(B\)` is the number of endogenous regressors; `\(L\)` is the number of external instruments; `\(r_B\)` is the lowest canonical correlation. > **Canonical correlation** is a measure of the correlation between the endogenous and the exogenous variables, which can be calculated by the function `cancor()` in `R`. ??? external (ɪkˈstɜːnl) Canonical (kəˈnɒnɪkl) --- ### Hour example: backgound Let us construct another IV model with two endogenous regressors. We assumed the following work hours determination model: `$$hushrs=\beta_{1}+\beta_{2} mtr+\beta_{3} educ+\beta_{4} kidsl6+\beta_{5} nwifeinc+e$$` > - `\(hushrs\)`: work hours of husband, 1975 - `\(mtr\)`: federal marriage tax rate on woman - `\(kidslt6\)`: have kids < 6 years (dummy variable) - `\(nwifeinc\)`: wife’s net income There are: - Two **endogenous variables**: `\(educ\)` and `\(mtr\)` - Two **exogenous regressors**: `\(nwifeinc\)` and `\(kidslt6\)` - And two external **instruments**: `\(motheduc\)` and `\(fatheduc\)`. --- ### Hour example: Cragg-Donald test (R code) The data set is still `mroz`, restricted to women that are in the labor force(`\(inlf=1\)`). .scroll-box-16[ ``` r # filter samples mroz1 <- wooldridge::mroz %>% filter(wage>0, inlf==1) # set parameters N <- nrow(mroz1); G <- 2; B <- 2; L <- 2 # for endogenous variables x1 <- resid(lm( mtr ~ kidslt6 + nwifeinc, data = mroz1)) x2 <- resid(lm( educ ~ kidslt6 + nwifeinc, data = mroz1)) # for instruments z1 <-resid(lm(motheduc ~ kidslt6 + nwifeinc, data = mroz1)) z2 <-resid(lm(fatheduc ~ kidslt6 + nwifeinc, data=mroz1)) # column bind X <- cbind(x1,x2) Y <- cbind(z1,z2) # calculate Canonical correlation rB <- min(cancor(X,Y)$cor) # obtain the F statistics CraggDonaldF <- ((N-G-L)/L)/((1-rB^2)/rB^2) ``` ] .footnote[ R script download: [`Cragg-Donald-test.R`](scripts/chapter17/chunk-sources/Cragg-Donald-test.R) ] --- ### Hour example: Cragg-Donald test (result) Run these code lines, we can obtain the results: Table: Cragg-Donald test results | G | L | B | N | rb | CraggDonaldF | |:-:|:-:|:-:|:---:|:------:|:------------:| | 2 | 2 | 2 | 428 | 0.0218 | 0.1008 | The result show the Cragg-Donald `\(F=\)` 0.1008 , which is much smaller than **the critical value** `4.58`<sup>[1]</sup>. This test can not rejects the null hypothesis, thus we may conclude that some of these instruments are **weak**. .footnote[ [1] The critical value can be found in table 10E.1 at: Hill C, Griffiths W, Lim G. Principles of econometrics[M]. John Wiley & Sons, 2018. ] ??? You can inquire the critical values in Table 10E.1 of the textbook,Hill, Griffiths, and Lim 2011. --- ### Instrument Exogeneity: the difficulty **Instrument Exogeneity** means all `\(m\)` instruments must be uncorrelated with the error term, `$$Cov{(Z_{1 i}, \epsilon_{i})}=0; \quad \ldots; \quad Cov{(Z_{mi}, \epsilon_{i})}=0.$$` - In the context of the simple IV estimator, we will find that the exogeneity requirement **can not** be tested. (Why?) - However, if we have more instruments than we need, we can effectively test whether **some of** them are uncorrelated with the structural error. ??? As we know , when we call a instrument is validity, we should also check that it satisfy the exogeneity condition. --- ### Instrument Exogeneity: over-identification case Under **over-identification** `\((m>k)\)`, consistent IV estimation with (multiple) different combinations of instruments is possible. > If instruments are exogenous, the obtained estimates should be **similar**. > If estimates are very **different**, some or all instruments may .red[not] be exogenous. The **Overidentifying Restrictions Test** (**J test**) formally check this. - The null hypothesis is Instrument Exogeneity. `$$H_{0}: E\left(Z_{h i} \epsilon_{i}\right)=0, \text { for all } h=1,2, \dots, m$$` --- ### Instrument Exogeneity: J-test (procedure) The **overidentifying restrictions test** (also called the `\(J\)`-test, or **Sargan test**) is an approach to test the hypothesis that the additional instruments are exogenous. Procedure of overidentifying restrictions test is: - **Step 1**: Compute the **IV regression residuals** : `$$\widehat{\epsilon}_{i}^{IV}=Y_{i}-\left(\hat{\beta}_{0}^{ IV}+\sum_{j=1}^{k} \hat{\beta}_{j}^{IV} X_{j i}+\sum_{s=1}^{r} \hat{\beta}_{k+s}^{IV} W_{s i}\right)$$` - **Step 2**: Run the **auxiliary regression**: regress the IV residuals on instruments and exogenous regressors. And test the joint hypothesis `\(H_{0}: \alpha_{1}=0, \ldots, \alpha_{m}=0\)` `$$\widehat{\epsilon}_{i}^{IV}=\theta_{0}+\sum_{h=1}^{m} \theta_{h} Z_{h i}+\sum_{s=1}^{r} \gamma_{s} W_{s i}+v_{i} \quad \text{(2)}$$` ??? auxiliary (ɔːɡˈzɪliəri) --- ### Instrument Exogeneity: J-test (procedure) - **Step3**: Compute the **J statistic**: `\(J=m F\)` > where `\(F\)` is the F-statistic of the `\(m\)` restrictions `\(H_0: \theta_{1}=\ldots=\theta_{m}=0\)` in eq(2) Under the **null hypothesis**, `\(J\)` statistic is distributed as `\(\chi^{2}(m-k)\)` approximately for large samples( `\(k=\)` numbers of endogenous regressor ). `$$\boldsymbol{J} \sim \chi^{2}({m-k})$$` > IF `\(J\)` is **less** than **critical value**, it means that all instruments are .red[ex]ogenous. > IF `\(J\)` is **larger** than **critical value**, it mean that some of the instruments are .red[en]ogenous. - We can apply the `\(J\)`-test by using `R` function `linearHypothesis()`. ??? approximately (əˈprɒksɪmətli) --- ### Wage example: J-test (models) Again, we can use both `\(matheduc\)` and `\(fatheduc\)` as instruments for `\(educ\)`. Thus, the IV model is over-identification, and we can test the exogeneity of both these two instruments by using **J-test**. The 2SLS model will be set as below. `$$\begin{cases} \begin{align} \widehat{educ} &= \hat{\gamma}_1 +\hat{\gamma}_2exper + \hat{\beta}_3expersq +\hat{\beta}_4motheduc + \hat{\beta}_5fatheduc && \text{(stage 1)}\\ lwage & = \hat{\beta}_1 +\hat{\beta}_2\widehat{educ} + \hat{\beta}_3exper +\hat{\beta}_4expersq + \hat{\epsilon} && \text{(stage 2)} \end{align} \end{cases}$$` And the auxiliary regression should be `$$\begin{align} \hat{\epsilon}^{IV} &= \hat{\alpha}_1 +\hat{\alpha}_2exper + \hat{\alpha}_3expersq +\hat{\theta}_1motheduc + \hat{\theta}_2fatheduc + v && \text{(auxiliary model)} \end{align}$$` --- ### Wage example: J-test (R code for 2SLS residuals) We have done the 2SLS estimation before, the `R` code using `ivreg::ivreg()`: ``` r # load pkg require(AER) # specify model mod_iv_mf <- formula( lwage ~ educ + exper + expersq | motheduc + fatheduc + exper + expersq) # fit model lm_iv_mf <- ivreg(formula = mod_iv_mf, data = mroz) # summary of model fit smry.ivmf <- summary(lm_iv_mf) ``` .footnote[ R script download: [`ivreg-mf.R`](scripts/chapter17/chunk-sources/ivreg-mf.R) ] After the 2SLS estimation, we can obtain the IV residuals of the second stage: ``` r # obtain residual of IV regression, add to data set mroz_resid <- mroz %>% mutate(resid_iv_mf = residuals(lm_iv_mf)) ``` --- ### Wage example: J-test (new data set)
??? This table shows the new data set after adding the IV estimation residuals. --- ### Wage example: J-test (run auxiliary regression) .panelset[ .panel[.panel-name[R Code] We run the auxiliary regression with `R` code lines: ``` r # set model formula mod_jtest <- formula(resid_iv_mf ~ exper +expersq +motheduc +fatheduc) # OLS estimate lm_jtest <- lm(formula = mod_jtest, data = mroz_resid) ``` Then we can obtain the OLS estimation results. ] .panel[.panel-name[R result] .scroll-box-20[ ``` Call: lm(formula = mod_jtest, data = mroz_resid) Residuals: Min 1Q Median 3Q Max -3.1012 -0.3124 0.0478 0.3602 2.3441 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 1.096e-02 1.413e-01 0.078 0.938 exper -1.833e-05 1.333e-02 -0.001 0.999 expersq 7.341e-07 3.985e-04 0.002 0.999 motheduc -6.607e-03 1.189e-02 -0.556 0.579 fatheduc 5.782e-03 1.118e-02 0.517 0.605 Residual standard error: 0.6752 on 423 degrees of freedom Multiple R-squared: 0.0008833, Adjusted R-squared: -0.008565 F-statistic: 0.0935 on 4 and 423 DF, p-value: 0.9845 ``` ] ] ] ??? Remind that the model summary gives a F test result, which is differnt with the F statistic in J-test. --- ### Wage example: J-test (Restricted F-test) As what we have done before, We conduct the restrict F-test for the auxiliary regression. .panelset[ .panel[.panel-name[R Code] We will restrict jointly with `\(\theta_1 = \theta_2 =0\)`, and using the R function `linearHypothesis()`: ``` r # restricted F-test restricted_ftest <- linearHypothesis(lm_jtest, c("motheduc = 0", "fatheduc = 0"), test = "F") # obtain the F statistics restricted_f <- restricted_ftest$F[[2]] ``` ] .panel[.panel-name[R result] ``` Linear hypothesis test: motheduc = 0 fatheduc = 0 Model 1: restricted model Model 2: resid_iv_mf ~ exper + expersq + motheduc + fatheduc Res.Df RSS Df Sum of Sq F Pr(>F) 1 425 193.02 2 423 192.85 2 0.1705 0.187 0.8295 ``` ] ] The restricted F-statistics is 0.1870 (with round digits 4 here ). ??? Please pay attention to the code `c("motheduc = 0", "fatheduc = 0")` --- ### Wage example: J-test (calculate J-statistic by hand) Finally, We can calculate J-statistic by hand or obtain it by using special tools. - Calculate J-statistic by hand ``` r # numbers of instruments m <- 2 # calculate J statistics (jtest_calc <- m*restricted_f) ``` ``` [1] 0.373985 ``` - The calculated J-statistic is 0.3740 (with round digits 4 here ). --- ### Wage example: J-test (obtain J-statistic with tools) Also, We can obtain J-statistic by using special tools. .panelset[ .panel[.panel-name[R Code] - using tools of `linearHypothesis(., test = "Chisq")` ``` r # chi square test directly jtest_chitest <- linearHypothesis( lm_jtest, c("motheduc = 0", "fatheduc = 0"), test = "Chisq") # obtain the chi square value jtest_chi <- jtest_chitest$Chisq[2] ``` ] .panel[.panel-name[R result] - The chi square test result: ``` Linear hypothesis test: motheduc = 0 fatheduc = 0 Model 1: restricted model Model 2: resid_iv_mf ~ exper + expersq + motheduc + fatheduc Res.Df RSS Df Sum of Sq Chisq Pr(>Chisq) 1 425 193.02 2 423 192.85 2 0.1705 0.374 0.8294 ``` ] ] - We obtain the J-statistic 0.3740 (with round digits 4 here ). It's the same as what we have calculated by hand! ??? In `R`, we can use the function `linearHypothesis(., test = "Chisq")` by setting argument `test = "Chisq"`. Please check that the relations between restricted F statistics and the `\(\chi^2\)` statistics. --- ### Wage example: J-test (adjust the freedoms) .notes[ **Caution**: In this case the `\(p\)`-Value reported by `linearHypothesis(., test = "Chisq")` is wrong because the degrees of freedom are set to 2, and the correct freedom should be `\((m-k)=1\)`. ] - We have obtain the J statistics `\({\chi^2}^{\ast} =0.3740\)`, and its correct freedom is `\((m-k)=1\)`. - Then we may compute the correct `\(p\)`-Value of this the J statistics (by using function `pchisq()` in `R`). ``` r # correct freedoms f <- m -1 # compute correct p-value for J-statistic (pchi <- pchisq(jtest_chi, df = f, lower.tail = FALSE)) ``` ``` [1] 0.5408401 ``` ??? This differs from the degree of overidentification ( `\(m−k=2−1=1\)`). So the `\(J\)`-statistic is `\(\chi^2(1)\)` distributed instead of following a `\(\chi^2(2)\)` distribution as assumed defaultly by `linearHypothesis()`. --- ### Wage example: J-test (the conclutions) Now we can get the conclusions of J-test. Since the p-value of J-test(0.5408)is larger than the criteria value 0.1, we can't reject the null hypothesis that both instruments are exogenous. This means both instruments( `motheduc` and `fatheduc`) are **exogenous**. ??? Finally, we go through all instrument validity tests in this section. the next section we will illustrate how to test regressor endogeneity. ### 2SLS as a weighted average of just-identified IVs Another useful view of **2SLS** when `\(L > J\)`: `$$\begin{aligned} \beta^{2SLS} & = \left(\pi' \operatorname{Cov}(\tilde{Z}_i, X_i')\right)^{-1} \pi' \operatorname{Cov}(\tilde{Z}_i, Y_i) \\ & = \left(\pi' \operatorname{Var}(\tilde{Z}_i) \pi\right)^{-1} \pi' \operatorname{Var}(\tilde{Z}_i) \rho \end{aligned}$$` This is a `\(\operatorname{Var}(\tilde{Z}_i)\)`-weighted regression of reduced-form coefficients `\(\rho\)` on first-stage coefficients `\(\pi\)` (through the origin). - When `\(J = 1\)`: `\(\beta^{2SLS} = \sum_\ell \omega_\ell \beta_\ell^{IV}\)` where each `\(\beta_\ell^{IV} = \rho_\ell / \pi_\ell\)` uses one instrument at a time. - Intuition: 2SLS **combines** multiple one-at-a-time IV estimands, weighting by first-stage strength. --- ### Overidentification tests: caveats Under a **constant-effects** model, overidentification checks whether all just-identified IVs agree (`\(\beta_\ell^{IV} = \beta\)` for all `\(\ell\)`). - The **J-test** / **Sargan test** (above) implements this when `\(L > J\)`. **Do not over-interpret rejections:** - Tests often have **low power** (each `\(\hat{\beta}_\ell^{IV}\)` is noisy). - Rejection need **not** mean invalid instruments — **treatment effect heterogeneity** can make valid IVs differ. - Rejection does **not** identify which instrument fails. --- ### Class Exercise: three IVs for `educ` For the wage case, and the origin model(Mis-specificated) was assumed to have only one endogenous variable(`educ`) `$$\begin{align} lwage = {\beta}_1 +{\beta}_2{educ} + {\beta}_3exper +{\beta}_4expersq + {\epsilon} \end{align}$$` If we add husband’s education(`huseduc`) to the IV list, then we will have totally three IVs (`fatheduc`, `motheduc` and `huseduc`) for `educ`. - Use these three IVs to obtain TSLS results. Compare the TSLS results when using two IVs(`fatheduc` and `motheduc`) which we have got. - Conduct the over-identification test (J-test). --- layout: false class: center, middle, duke-softblue,hide_logo name: endogeneity ## 17.8 Testing Regressor endogeneity ??? In this section, we focus mainly on regressor endogeneity issues. --- layout: true <div class="my-header-h2"></div> <div class="watermark1"></div> <div class="watermark2"></div> <div class="watermark3"></div> <div class="my-footer"><span>huhuaping@ <a href="#chapter17"> Chapter 17. Endogeneity and Instumental Variables |</a>               <a href="#endogeneity"> 17.8 Testing Instrument endogeneity </a></span></div> --- ### Regressor Endogeneity: the concepts It is the researcher’s responsibility to specify which variables are endogenous and which are exogenous. So, how can we test the regressor endogeneity? Since OLS is in general more efficient than IV (recall that if Gauss-Markov assumptions hold OLS is BLUE), we don't want to use IV when we don't need to get the consistent estimators. Of course, if we really want to get a consistent estimator, we also need to check whether the endogenous regressors are really **endogenous** in the model. So we should test following hypothesis: `$$H_{0}: \operatorname{Cov}(X, \epsilon)=0 \text { vs. } H_{1}: \operatorname{Cov}(X, \epsilon) \neq 0$$` --- ### Regressor Endogeneity: Hausman test `Hausman` tells us that we should use OLS if we fail to reject `\(H_{0}\)`. And we should use IV estimation if we reject `\(H_{0}\)` Let's see how to construct a `Hausman test`. While the idea is very simple. - If `\(X\)` is **.red[ex]ogenous** in fact, then both OLS and IV are consistent, but OLS estimates are more efficient than IV estimates. - If `\(X\)` is **.red[en]dogenous** in fact, then the results from OLS estimators are different, while results obtained by IV (eg. 2SLS) are consistent. .footnote[ In fact, the general class of tests are called **Durbin-Wu-Hausman** tests, **Wu-Hausman** tests, or **Hausman** tests. ] --- ### Hausman test: the idea We can compare the difference between estimates computed using both OLS and IV. - If the difference is **small**, we can conjecture that both OLS and IV are consistent and the small difference between the estimates is not systematic. - If the difference is **large** this is due to the fact that OLS estimates are not consistent. We should use IV in this case. --- ### Hausman test: the statistics The **Hausman test** takes the following statistics form ( `\(k=\)` numbers of edogenous regressor ) `$$\begin{align} \hat{H}=n\boldsymbol{\left[\hat{\beta}_{IV}-\hat{\beta}_{\text {OLS}}\right] ^{\prime}\left[\operatorname{Var}\left(\hat{\beta}_{IV}-\hat{\beta}_{\text {OLS}}\right)\right]^{-1}\left[\hat{\beta}_{IV}-\hat{\beta}_{\text {OLS}}\right]} \xrightarrow{d} \chi^{2}(k) \end{align}$$` - If `\(\hat{H}\)` is less than the critical `\(\chi^2\)` value, we can not reject the null hypothesis, and the regressor should **not be endogenous**. - If `\(\hat{H}\)` is **larger** than the critical `\(\chi^2\)` value, the null hypothesis is rejected , and the regressor should **be endogenous**. .footnote[ The three authors' approaches yield the same statistic except for possible differences regarding the choice of `\(\hat{\sigma}^2\)`. - Durbin (1954) proposed setting `\(\hat{\sigma}^2\)` to be the OLS estimator of `\(\sigma^2\)`. - Wu (1973) proposed a set of possible estimator `\(\hat{\sigma}^2\)`. - Hausman (1978) proposed a Wald statistic. ] --- ### Hausman test: the procedure The origin model is `$$\begin{align} Y_{i}=\hat{\alpha}_{0} + \alpha_1 X_i+\hat{\beta}_{1} W_{1 i}+\ldots+\hat{\beta}_{p} W_{p i} +u_{i} \quad \text{(origin model)} \end{align}$$` - Conduct the **first-stage regression** of 2SLS estimation and obtain the residuals `\(v_i\)`. `$$\begin{align} X_{i}=\hat{\gamma}_{0}+\hat{\gamma}_{1} W_{1 i}+\ldots+\hat{\gamma}_{p} W_{p i}+ \hat{\theta}_{1} Z_{1 i}+\ldots+\hat{\theta}_{q} Z_{q i}+v_{i} \quad \text{(reduced model)} \end{align}$$` - Then estimate the control function by least squares `$$\begin{align} Y_{i}=\hat{\delta}_{0} + \hat{\delta}_1 X_i + \hat{\delta}_{1} W_{1 i}+\ldots+\hat{\delta}_{p} W_{p i}+ \hat{\lambda}_{1} v_i+ u_{i} \quad \text{(control model)} \end{align}$$` - Conduct the **Restricted F-test** with `\(H_0: \lambda_1=0\)` (**Wu-Hausman F-test**). - If the `\(F\)`-statistic is lager than critical value, the regressor `\(X_i\)` is **Endogenous**. .footnote[ The restricted F statistics is equivalent to the square of t statistics of `\(\hat{\lambda}\)` in the control function, which is `\(t^2_{\hat{\lambda}} = F^{\ast} \quad \text{(Wu-Hausman F)}\)` ] --- ### Wage example: Hausman test (the origin & IV model) The origin model is `$$\begin{aligned} lwage & = \hat{\alpha}_0 +\hat{\alpha}_1 {educ} + \hat{\beta}_1 exper +\hat{\beta}_2 expersq + u_i && \text{(origin model)} \end{aligned}$$` Again, we use both `\(matheduc\)` and `\(fatheduc\)` as instruments for `\(educ\)` in our IV model setting. `$$\begin{cases} \begin{align} {educ} &= \hat{\gamma}_0 +\hat{\gamma}_1exper + \hat{\gamma}_2expersq + \hat{\theta}_1motheduc + \hat{\theta}_2fatheduc +v_i && \text{(stage 1)}\\ lwage & = \hat{\eta}_1 +\hat{\eta}_2\widehat{educ} + \hat{\eta}_3exper +\hat{\eta}_4expersq + e_i && \text{(stage 2)} \end{align} \end{cases}$$` --- ### Wage example: Hausman test (R solutions) In `R`, we have at least two equivalent solutions to conduct Hausman test: - Solution 1 (Automatically) : We can use IV model **diagnose tool** to check the Hausman test results. In fact, `R` function `summary(lm_iv_mf, diagnostics = TRUE)` by setting `diagnostics = TRUE` will give you these results (**Wu-Hausman F**). - Solution 2 (Calculate by hand) : With Step-by-step calculation according to the procedures, you can obtain the **Wu-Hausman F** statistics. So let's try both of these solutions! --- ### Wage example: Hausman test (Solution 1 diagnose) .scroll-box-18[ .panelset[ .panel[.panel-name[R Code] ``` r require(AER) mod_iv_mf <- formula( lwage ~ educ + exper + expersq | motheduc + fatheduc + exper + expersq) lm_iv_mf <- ivreg(formula = mod_iv_mf, data = mroz) summary(lm_iv_mf, diagnostics = TRUE) ``` ] .panel[.panel-name[R Result] ``` r ### ==== solution 1 for Hausman test (full model diagnose) ==== summary(lm_iv_mf, diagnostics = TRUE) ``` ``` Call: AER::ivreg(formula = lwage ~ educ + exper + expersq | motheduc + fatheduc + exper + expersq, data = mroz) Residuals: Min 1Q Median 3Q Max -3.0986 -0.3196 0.0551 0.3689 2.3493 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 0.0481003 0.4003281 0.120 0.90442 educ 0.0613966 0.0314367 1.953 0.05147 . exper 0.0441704 0.0134325 3.288 0.00109 ** expersq -0.0008990 0.0004017 -2.238 0.02574 * Diagnostic tests: df1 df2 statistic p-value Weak instruments 2 423 55.400 <2e-16 *** Wu-Hausman 1 423 2.793 0.0954 . Sargan 1 NA 0.378 0.5386 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 0.6747 on 424 degrees of freedom Multiple R-Squared: 0.1357, Adjusted R-squared: 0.1296 Wald test: 8.141 on 3 and 424 DF, p-value: 2.787e-05 ``` ] ] ] .footnote[ R script download: [`ivreg-mf-diagnostics.R`](scripts/chapter17/chunk-sources/ivreg-mf-diagnostics.R) ] --- ### Wage example: Hausman test (Solution 2 calculation) .scroll-box-18[ .panelset[ .panel[.panel-name[R Code] ``` r ### ==== solution 2 for Hausman test (calculate) ==== ## guide with Hansen's chpt 12.29 Endogeneity test ## reduced function for endogenous education red_mf <- formula(educ ~ exper + expersq + motheduc + fatheduc) fit_red_mf<- lm(formula = red_mf, data = mroz) ## extract residual u2 and combined new dataset resid_mf <- data.frame(resid_mf = resid(fit_red_mf)) tbl_mf <- cbind(mroz, resid_mf) ## control function OLS estimation control_mf <- formula(lwage ~ educ +exper + expersq + resid_mf) fit_control_mf <- lm(formula = control_mf, data = tbl_mf) smry_control_mf <- summary(fit_control_mf) ## extract t statistics of alpha t_star_resid <- pull( as_tibble(t(smry_control_mf$coefficients[,"t value"])), "resid_mf") ## calculate equivalent F statistics restricted_F_mf <- linearHypothesis(model = fit_control_mf, "resid_mf=0") F_star_resid <- restricted_F_mf$F[2] p_F_resid <- restricted_F_mf$`Pr(>F)`[2] ``` ] .panel[.panel-name[Result 1] ``` r # the OLS result of control model smry_control_mf ``` ``` Call: lm(formula = control_mf, data = tbl_mf) Residuals: Min 1Q Median 3Q Max -3.03743 -0.30775 0.04191 0.40361 2.33303 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 0.0481003 0.3945753 0.122 0.903033 educ 0.0613966 0.0309849 1.981 0.048182 * exper 0.0441704 0.0132394 3.336 0.000924 *** expersq -0.0008990 0.0003959 -2.271 0.023672 * resid_mf 0.0581666 0.0348073 1.671 0.095441 . --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 0.665 on 423 degrees of freedom Multiple R-squared: 0.1624, Adjusted R-squared: 0.1544 F-statistic: 20.5 on 4 and 423 DF, p-value: 1.888e-15 ``` ] .panel[.panel-name[Result 2] ``` r # t statistics number(t_star_resid, 0.0001) ``` ``` [1] "1.6711" ``` ``` r # F statistics and probability number(F_star_resid, 0.01) ``` ``` [1] "2.79" ``` ``` r number(p_F_resid, 0.001) ``` ``` [1] "0.095" ``` ] ] ] --- ### Wage example: the diagnosed conclusions The results for the lwage equation are as follows: - **(Wu-)Hausman test** for endogeneity: **barely reject** the null that the variable of concern is uncorrelated with the error term, indicating that `educ` is marginally endogenous. The Hausman statistics `\(\hat{H}= {\chi^2}^{\ast} = 2.79\)`, and its p-value is 0.095. - **Weak instruments test**: **rejects** the null hypothesis(Weak instruments). At least one of these instruments(`motheduc` or `fatheduc`) is strong. The **restricted F-test** statistics `\(F^{\ast}_R = 55.4\)`, and its p-value is 0.0000. - **Sargan overidentifying restrictions**(Instruments exogeneity J-test): **does not** reject the null. The extra instruments (`motheduc` and `fatheduc`) are valid (both are exogenous, and are uncorrelated with the error term). ??? So far, We have finished both the instrument validity test and the regressor endogeneity test. Now, I will show you two examples. You can download the data set and go through all these test we have discussed. --- ### Summary - An **instrumental variable** must have two properties: - (1) it must be exogenous, that is, uncorrelated with the error term of the structural equation; - (2) it must be partially correlated with the endogenous explanatory variable. > Finding a variable with these two properties is usually challenging. - Though we can **never** test whether .red[all] IVs are **exogenous**, we can test that at least .red[some of] them are. - When we have valid instrumental variables, we can test whether an explanatory variable is **endogenous**. - The method of **two stage least squares** is used routinely in the empirical social sciences. > But when instruments are poor, then 2SLS can be **worse** than OLS. --- layout: false class: center, middle, duke-softblue,hide_logo name: exercise ## Exercise and Computation --- layout: true <div class="my-header-h2"></div> <div class="watermark1"></div> <div class="watermark2"></div> <div class="watermark3"></div> <div class="my-footer"><span>huhuaping@ <a href="#chapter17"> Chapter 17. Endogeneity and Instumental Variables |</a>               <a href="#exercise"> Exercise and Computation </a></span></div> --- ### Card wage case: introduction With data set `Card1995.dta`, researchers were interest in the return (`log(Wage)`) to education (`edu`), and they mainly focus the effect of students living region nearby the college. In a influential paper David Card (1995) suggested if a potential student lives close to a college this reduces the cost of attendance and thereby raises the likelihood that the student will attend college. However, college proximity does not directly affect a student’s skills or abilities so should not have a direct effect on his or her market wage. The origin model is `$$\begin{aligned} lwage & = \hat{\alpha}_0 +\hat{\alpha}_1 {educ} + \hat{\alpha}_3 exp +\hat{\alpha}_4 exp2 +\hat{\alpha}_5 black +\hat{\alpha}_6 south +\hat{\alpha}_7 urban + u_i \end{aligned}$$` .footnote[ Please follow our accompany course repository at <https://github.com/huhuaping/course-emiii-accompany> or <https://gitee.com/kevinhhp/course-emiii-accompany>. ] --- ### Card wage case: variables
--- ### Card wage case: models and IV list sets Let's consider following estimation solutions: a. Error specification model with OLS regression directly. b. Equivalent IVs for endogenous regressors (just- identificaion) - The IV model using `college` as instruments for `educ` - The IV model using (`college`, `age`, `age2`) as instruments for (`edu`,`exp`,`exp2`) c. Abundant IVs for endogenous regressors (over-identification) - The IV model using both (`public`,`private`) as instruments for `educ` - The IV model using both (`public`,`private`,`age`,`age2`) as instruments for (`edu`, `exp`,`exp2`) --- ### Equivalent IVs (TSLS 1/4) we will use `college` as instruments for `educ` in our IV model setting. `$$\begin{cases} \begin{align} {edu} &= \hat{\gamma}_0 +\hat{\gamma}_1exp + \hat{\gamma}_2exp2 + \hat{\gamma}_3black + \hat{\gamma}_4south + \hat{\gamma}_5urban + \hat{\theta}_1college +v_i && \text{(stage 1)}\\ lwage & = \hat{\eta}_1 +\hat{\eta}_2\widehat{edu} + \hat{\eta}_3exp +\hat{\eta}_4exp2 +\hat{\eta}_5 black +\hat{\eta}_6 south +\hat{\eta}_7 urban+ e_i && \text{(stage 2)} \end{align} \end{cases}$$` --- ### Equivalent IVs (TSLS 2/4) we will use (`college`, `age`, `age2`) as instruments for (`edu`,`exp`,`exp2`) in our IV model setting. `$$\begin{cases} \begin{align} {edu} &= \hat{\gamma}_0 +\hat{\gamma}_1age + \hat{\gamma}_2age2 + \hat{\gamma}_3black + \hat{\gamma}_4south + \hat{\gamma}_5urban + \hat{\theta}_1college +v_{1i} && \text{(1 of stage 1)}\\ {exp} &= \hat{\lambda}_0 +\hat{\lambda}_1age + \hat{\lambda}_2age2 + \hat{\lambda}_3black + \hat{\lambda}_4south + \hat{\lambda}_5urban + \hat{\lambda}_1college +v_{2i} && \text{(2 of stage 1)}\\ {exp2} &= \hat{\delta}_0 +\hat{\delta}_1age + \hat{\delta}_2age2 + \hat{\delta}_3black + \hat{\delta}_4south + \hat{\delta}_5urban + \hat{\delta}_1college +v_{3i} && \text{(3 of stage 1)}\\ lwage & = \hat{\eta}_1 +\hat{\eta}_2\widehat{edu} + \hat{\eta}_3exp +\hat{\eta}_4exp2 +\hat{\eta}_5 black +\hat{\eta}_6 south +\hat{\eta}_7 urban+ e_i && \text{(stage 2)} \end{align} \end{cases}$$` --- ### Abundant IVs (TSLS 3/4) we will use both (`public`,`private`) as instruments for `educ` in our IV model setting. `$$\begin{cases} \begin{align} {edu} &= \hat{\gamma}_0 +\hat{\gamma}_1exp + \hat{\gamma}_2exp2 + \hat{\gamma}_3black + \hat{\gamma}_4south + \hat{\gamma}_5urban && \\&+ \hat{\theta}_1public + \hat{\theta}_2private +v_i && \text{(stage 1)}\\ lwage & = \hat{\eta}_1 +\hat{\eta}_2\widehat{edu} + \hat{\eta}_3exp +\hat{\eta}_4exp2 +\hat{\eta}_5 black &&\\ &+\hat{\eta}_6 south +\hat{\eta}_7 urban+ e_i && \text{(stage 2)} \end{align} \end{cases}$$` --- ### Abundant IVs (TSLS 4/4) we will use both (`public`,`private`,`age`,`age2`) as instruments for (`edu`, `exp`,`exp2`) in our IV model setting. `$$\begin{cases} \begin{align} {edu} &= \hat{\gamma}_0 +\hat{\gamma}_1age + \hat{\gamma}_2age2 + \hat{\gamma}_3black + \hat{\gamma}_4south + \hat{\gamma}_5urban &&\\ & + \hat{\theta}_1public + \hat{\theta}_2private +v_{1i} && \text{(1 of stage 1)}\\ {exp} &= \hat{\lambda}_0 +\hat{\lambda}_1age + \hat{\lambda}_2age2 + \hat{\lambda}_3black + \hat{\lambda}_4south + \hat{\lambda}_5urban &&\\ &+ \hat{\lambda}_1public + \hat{\lambda}_2private +v_{2i} && \text{(2 of stage 1)}\\ {exp2} &= \hat{\delta}_0 +\hat{\delta}_1age + \hat{\delta}_2age2 + \hat{\delta}_3black + \hat{\delta}_4south + \hat{\delta}_5urban &&\\ &+ \hat{\delta}_1public + \hat{\delta}_2private +v_{3i} && \text{(3 of stage 1)}\\ lwage & = \hat{\eta}_1 +\hat{\eta}_2\widehat{edu} + \hat{\eta}_3exp +\hat{\eta}_4exp2 +\hat{\eta}_5 black &&\\ &+\hat{\eta}_6 south +\hat{\eta}_7 urban+ e_i && \text{(stage 2)} \end{align} \end{cases}$$` --- ### Exercise tasks 1/2: compare all results .scroll-box-20[
] --- ### Exercise tasks 2/2: conduct several tests So we should conduct several tests as we have learned. - Weak instrument test (Restricted F test or Cragg-donald test) - Instrument Exogeneity test (J-test ) - Regressor Endogeneity test (Wu-Hausman test) Find these results and get the conclusion! --- layout:false background-image: url("../pic/thank-you-gif-funny-little-yellow.gif") class: inverse,center # End Of This Chapter ??? So we finished all content of chapter 17. The next three chapters will focus on SEM closely. See you in the next class. if you have questions, please let me know. you can leave messages by QQ or email. Thanks. Goodbye!