class: center, middle, inverse, title-slide .title[ # Estimación por variables instrumentales (IV) ] .author[ ### Erika R. Badillo
erika.badilloen@unaula.edu.co
] .date[ ###
Econometría II
Programa de Economía
Universidad Autónoma Latinoamericana
] --- <style> .notbold{ font-weight:normal } body { text-align: justify; } h1{ margin-top: -1px; margin-bottom: -3px; } .small-code pre{ margin-bottom: -10px; } .medium-code pre{ margin-bottom: 2px; } </style> <font size = "5"> # <span style="font-size:80%">En este tema</span> - <span style="font-size:150%"> [<span style="color:black">Ejercicio aplicado en R: efectos de la educación de la mujer sobre la fertilidad](#ejercicio)</span> --- # <span style="font-size:80%">Lecturas adicionales</span> - <span style="font-size:150%">Wooldridge, J. (2010). *Econometric Analysis of Cross Section and Panel Data*. 2a edición. MA: MIT Press. <span style="color:blue">Cap 5 <br> <br> - <span style="font-size:150%"> Greene, W. H. (2018). *Econometric Analysis*. 8th ed. NY: Pearson. <span style="color:blue">Cap 8 --- name: ejercicio # <span style="font-size:70%">Ejercicio aplicado: efectos de la educación de la mujer sobre la fertilidad</span> **Las mujeres más educadas tienen menos hijos?** Numerosos estudios indican que la educación de las mujeres tiene un efecto negativo sobre la fertilidad. Varias son las posibles explicaciones: - la escolarización aumenta el coste de oportunidad de tener un hijo - aumenta la eficiencia del control de fertilidad - simplemente reduce la preferencia por los hijos En este ejercicio vamos a estudiar este posible efecto negativo. El siguiente ejercicio se basa en el paper: McCrary, J y Royer, H. (2011). "The Effect of Female Education on Fertility and Infant Health: Evidence from School Entry Policies Using Exact Date of Birth". *American Economic Review*, 101: 158-195. Los datos para este ejercicio proviene de la *General Social Survey (GSS)* de los Estados Unidos. En los siguientes links se encuentran los datos, la descripción detallada de los datos y el código utilizado en R: - [Datos](https://ebadilloe.github.io/EconometriaII/IV/GSS2012_2018.dta) - [Descripción de la información](https://gss.norc.org/get-the-data/stata) - [Código en R](https://ebadilloe.github.io/EconometriaII/IV/IV_clase.R) --- # <span style="font-size:70%">Ejercicio aplicado: efectos de la educación de la mujer sobre la fertilidad</span> .small-code[ Cargando las librerías ``` r library(devtools); library(haven); library(dplyr); library(cragg); library(AER); library(tidyverse); library(stargazer); library(modelsummary) library(gt); library(knitr); library(kableExtra); library(tibble) ``` Leyendo los datos y procesando la información ``` r setwd("C:/Users/USUARIO/OneDrive - Universidad Autónoma Latinoamericana/1 Econometria/1 Econometria II-UNAULA/Clases/IV") data <- read_dta("GSS2012_2018.DTA") %>% # Leyendo el archivo .dta select(year, age, sex, race, educ, childs, paeduc, maeduc, wrkstat, marital) %>% # Seleccionando variables de la base filter(sex==2, year>=2014 & year<=2018, age>=35 & age<=55) %>% # Filtrando la base para mujeres y años mutate(age2 = age*age, afroa = case_when(race == 1 ~ 1, race == 2 ~ 0), working = case_when(wrkstat >= 1 & wrkstat<= 2 ~ 1, wrkstat >= 3 & wrkstat<= 8 ~ 0), casado = case_when(marital == 1 ~ 1, marital != 1 ~ 0)) %>% # Creando variables drop_na() # Borrando missings de toda la base ``` .pull-left-30[ ``` r data[,c("race","afroa")] ``` ``` # A tibble: 935 × 2 race afroa <dbl+lbl> <dbl> 1 1 [white] 1 2 1 [white] 1 3 1 [white] 1 4 1 [white] 1 5 2 [black] 0 6 1 [white] 1 7 1 [white] 1 8 1 [white] 1 9 1 [white] 1 10 2 [black] 0 # ℹ 925 more rows ``` ] .pull-left-30[ ``` r data[,c("wrkstat","working")] ``` ``` # A tibble: 935 × 2 wrkstat working <dbl+lbl> <dbl> 1 7 [keeping house] 0 2 1 [working fulltime] 1 3 3 [temp not working] 0 4 1 [working fulltime] 1 5 1 [working fulltime] 1 6 1 [working fulltime] 1 7 1 [working fulltime] 1 8 1 [working fulltime] 1 9 1 [working fulltime] 1 10 1 [working fulltime] 1 # ℹ 925 more rows ``` ] .pull-left-30[ ``` r data[,c("marital","casado")] ``` ``` # A tibble: 935 × 2 marital casado <dbl+lbl> <dbl> 1 5 [never married] 0 2 5 [never married] 0 3 5 [never married] 0 4 4 [separated] 0 5 5 [never married] 0 6 1 [married] 1 7 5 [never married] 0 8 1 [married] 1 9 1 [married] 1 10 5 [never married] 0 # ℹ 925 more rows ``` ] ] --- # <span style="font-size:70%">Ejercicio aplicado: efectos de la educación de la mujer sobre la fertilidad</span> .small-code[ .pull-left-50[ Estimación por OLS ``` r ols <- lm(childs ~ educ+age+I(age2)+casado+afroa+working, data=data) summary(ols) ``` ``` Call: lm(formula = childs ~ educ + age + I(age2) + casado + afroa + working, data = data) Residuals: Min 1Q Median 3Q Max -3.6795 -0.8997 -0.0462 0.7965 5.6386 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) -0.231814 2.675422 -0.087 0.93097 educ -0.136673 0.015867 -8.614 < 2e-16 *** age 0.204314 0.119975 1.703 0.08891 . I(age2) -0.002341 0.001328 -1.763 0.07820 . casado 0.471561 0.091202 5.171 2.86e-07 *** afroa -0.196362 0.124672 -1.575 0.11559 working -0.259425 0.098934 -2.622 0.00888 ** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 1.345 on 928 degrees of freedom Multiple R-squared: 0.1132, Adjusted R-squared: 0.1075 F-statistic: 19.75 on 6 and 928 DF, p-value: < 2.2e-16 ``` ] .pull-right-50[ Estimación por 2SLS ``` r iv <- ivreg(childs ~ educ+age+I(age2)+casado+afroa+working | age+I(age2)+casado+afroa+working+paeduc+maeduc, data=data) summary(iv) ``` ``` Call: ivreg(formula = childs ~ educ + age + I(age2) + casado + afroa + working | age + I(age2) + casado + afroa + working + paeduc + maeduc, data = data) Residuals: Min 1Q Median 3Q Max -4.01831 -0.89164 -0.05782 0.79643 5.53646 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 0.176497 2.699724 0.065 0.9479 educ -0.179672 0.032775 -5.482 5.42e-08 *** age 0.212482 0.120572 1.762 0.0784 . I(age2) -0.002446 0.001335 -1.832 0.0672 . casado 0.506371 0.094453 5.361 1.04e-07 *** afroa -0.200423 0.125194 -1.601 0.1097 working -0.196300 0.107859 -1.820 0.0691 . --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 1.351 on 928 degrees of freedom Multiple R-Squared: 0.1062, Adjusted R-squared: 0.1004 Wald test: 12.33 on 6 and 928 DF, p-value: 2.171e-13 ``` ] ] --- # <span style="font-size:70%">Ejercicio aplicado: efectos de la educación de la mujer sobre la fertilidad</span> <font size = "3"> .medium-code[ Utilizamos el paquete [```modelsummary```](https://vincentarelbundock.github.io/modelsummary/articles/modelsummary.html) para generar tablas editadas (Word, tex, text, png, html...) ``` r modelos <- list("OLS" = lm(childs ~ educ+age+I(age2)+casado+afroa+working, data=data), "IV" = ivreg(childs ~ educ+age+I(age2)+casado+afroa+working | age+I(age2)+casado+afroa+working+paeduc+maeduc, data=data)) cm <- c( '(Intercept)' = 'Constante', 'educ' = 'Educación', 'age' = 'Edad', 'I(age2)' = 'Edad2', 'casado' = 'Casado', 'afroa' = 'Afroamericano', 'working' = 'Empleado (=1)') cap <- 'Tabla 1. Determinantes de la fertilidad' modelsummary(modelos, output = 'gt', coef_map = cm, stars = c('*'=.1, '**'=.05, '***'=.01), statistic = "std.error", title = cap, gof_omit = 'IC|Log', coef_omit = "[^educ]") %>% tab_style(style = cell_text(size = 'medium'), locations = cells_body(rows = 1:6)) %>% tab_style(style = cell_text(color = 'red'), locations = cells_body(rows = 1)) %>% tab_source_note(source_note = "Nota: Errores estándar en paréntesis") %>% tab_style(style = cell_text(color = "black", size = "x-small"), locations = cells_source_notes()) ```
<caption class='gt_caption'>Tabla 1. Determinantes de la fertilidad</caption>
OLS
IV
Educación
-0.137***
-0.180***
(0.016)
(0.033)
Num.Obs.
935
935
R2
0.113
0.106
R2 Adj.
0.107
0.100
F
19.747
RMSE
1.34
1.35
* p < 0.1, ** p < 0.05, *** p < 0.01
Nota: Errores estándar en paréntesis
]