library(AER)
data(CollegeDistance)
# regress the log `wage` on `education` and save the result to `wage_mod_1`
# regress the log of `wage` on `education` and controls and save the result to `wage_mod_2`
# obtain robust coefficient summaries on both models
# regress the log of `wage` on `education` and save the result to `wage_mod_1`
wage_mod_1 <- lm(log(wage) ~ education, data = CollegeDistance)
# regress log of `wage` on `education` and controls and save the result to `wage_mod_2`
wage_mod_2 <- lm(log(wage) ~ unemp + ethnicity + gender + urban + education, data = CollegeDistance)
# obtain robust coefficient summaries on both models
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("Well done. The coefficient on education is positive but not significant, even if we augument the simple regression model by demographic control variables. This is due to endogeneity of education. Exercise 3 discusses the attempt of Card (1993) to circumvent this issue an asks you to apply it.")