if (requireNamespace("AER", quietly = TRUE)) withAutoprint({
library(AER)
data("CigarettesSW")
Cigs <- within(CigarettesSW, {
rprice <- price/cpi
rincome <- income/population/cpi
tdiff <- (taxs - tax)/cpi
})
iv_fit_AER <- AER::ivreg(log(packs) ~ log(rprice) + log(rincome) |
log(rincome) + tdiff + I(tax/cpi), data = Cigs)
vcovCR(iv_fit_AER, cluster = Cigs$state, type = "CR2")
coef_test(iv_fit_AER, vcov = "CR2", cluster = Cigs$state)
})
pkgs_available <-
requireNamespace("AER", quietly = TRUE) &
requireNamespace("ivreg", quietly = TRUE)
if (pkgs_available) withAutoprint ({
data("CigarettesSW")
Cigs <- within(CigarettesSW, {
rprice <- price/cpi
rincome <- income/population/cpi
tdiff <- (taxs - tax)/cpi
})
iv_fit_ivreg <- ivreg::ivreg(log(packs) ~ log(rprice) + log(rincome) |
log(rincome) + tdiff + I(tax/cpi), data = Cigs)
vcovCR(iv_fit_ivreg, cluster = Cigs$state, type = "CR2")
coef_test(iv_fit_ivreg, vcov = "CR2", cluster = Cigs$state)
})
Run the code above in your browser using DataLab