library(AER) data(CollegeDistance) # regresar el logaritmo de `wage` en `education` y guardar el resultado en `wage_mod_1` # regresar el logaritmo de `wage` en `education` y controles y guardar el resultado en `wage_mod_2` # obtener resúmenes robustos de coeficientes en ambos modelos # regresar el logaritmo de `wage` en `education` y guardar el resultado en `wage_mod_1` wage_mod_1 <- lm(log(wage) ~ education, data = CollegeDistance) # regresar el logaritmo de `wage` en `education` y controles y guardar el resultado en `wage_mod_2` wage_mod_2 <- lm(log(wage) ~ unemp + ethnicity + gender + urban + education, data = CollegeDistance) # obtener resúmenes robustos de coeficientes en ambos modelos coeftest(wage_mod_1, vcov. = vcovHC, type = "HC1") coeftest(wage_mod_2, vcov. = vcovHC, type = "HC1") test_or({ f <- ex() %>% override_solution("attach(CollegeDistance); wage_mod_1 <- lm(log(wage) ~ education); wage_mod_2 <- lm(log(wage) ~ unemp + ethnicity + gender + urban + education); coeftest(wage_mod_1, vcov. = vcovHC, type = \"HC1\"); coeftest(wage_mod_2, vcov. = vcovHC, type = \"HC1\")") f %>% check_function("lm", index = 1) %>% check_arg("formula") %>% check_equal() f %>% check_function("lm", index = 2) %>% check_arg("formula") %>% check_equal() f %>% check_object("wage_mod_1") f %>% check_object("wage_mod_2") f %>% check_function("coeftest", index = 1) %>% check_arg("vcov.") %>% check_equal() f %>% check_function("coeftest", index = 2) %>% check_arg("vcov.") %>% check_equal() },{ f <- ex() %>% override_solution("wage_mod_1 <- lm(log(CollegeDistance$wage) ~ CollegeDistance$education); wage_mod_2 <- lm(log(CollegeDistance$wage) ~ CollegeDistance$unemp + CollegeDistance$ethnicity + CollegeDistance$gender + CollegeDistance$urban + CollegeDistance$education); coeftest(wage_mod_1, vcov. = vcovHC, type = \"HC1\"); coeftest(wage_mod_2, vcov. = vcovHC, type = \"HC1\")") f %>% check_function("lm", index = 1) %>% check_arg("formula") %>% check_equal() f %>% check_function("lm", index = 2) %>% check_arg("formula") %>% check_equal() f %>% check_object("wage_mod_1") f %>% check_object("wage_mod_2") f %>% check_function("coeftest", index = 1) %>% check_arg("vcov.") %>% check_equal() f %>% check_function("coeftest", index = 2) %>% check_arg("vcov.") %>% check_equal() },{ test_function("lm", index = 1, args = "formula") test_function("lm", index = 2, args = "formula") test_function("coeftest", index = 1, args = c("x", "vcov.")) test_function("coeftest", index = 2, args = c("x", "vcov.")) }) success_msg("Bien hecho. El coeficiente de educación es positivo pero no significativo, incluso si se aumenta el modelo de regresión simple por variables de control demográfico. Esto se debe a la endogeneidad de la educación. El ejercicio 3 analiza el intento de Card (1993) de eludir este problema y pide que lo aplique.")