library(foreign) library(dplyr) data_URL <- "https://github.com/mca91/EconometricsWithR/blob/master/data/fastfood.dta?raw=true" dat <- read.dta(data_URL) dat <- dat %>% mutate(FTE = nmgrs + empft + (0.5 * emppt), FTE2 = nmgrs2 + empft2 + (0.5 * emppt2)) dat_NJ <- subset(dat, state == 1) dat_PA <- subset(dat, state == 0) reg_dat <- data.frame( rbind( data.frame(id = dat$sheet, chain = dat$chain, state = dat$state, empl = dat$FTE, D = 0), data.frame(id = dat$sheet, chain = dat$chain, state = dat$state, empl = dat$FTE2, D = 1))) library(AER) # estimate the DID model # obtain a robust summary of the model # estimate the DID model emp_did_mod <- lm(empl ~ D*state, data = reg_dat) # obtain a robust summary of the model coeftest(emp_did_mod, vcov. = vcovHC, type = "HC1") ex() %>% check_predefined_objects("reg_dat") ex() %>% check_object("emp_did_mod") %>% check_equal() check_or( ex() %>% check_function(., "lm") %>% { check_arg(., "formula") %>% check_equal() check_arg(., "data") %>% check_equal() }, ex() %>% override_solution("emp_did_mod <- lm(reg_dat$empl ~ reg_dat$D*reg_dat$state)") %>% check_function("lm") %>% check_arg("formula") %>% check_equal() ) check_or( ex() %>% check_function("coeftest") %>% { check_arg(., "x") %>% check_equal() check_arg(., "vcov.") %>% check_equal() }, ex() %>% override_solution("emp_did_mod <- lm(reg_dat$empl ~ reg_dat$D*reg_dat$state); coeftest(emp_did_mod, vcov. = vcovHC, type = 'HC1')") %>% check_function("coeftest") %>% { check_arg(., "x") %>% check_equal() check_arg(., "vcov.") %>% check_equal() } ) success_msg(msg = "Correct! The estimate of the coefficient on the interaction term `D:state` is the estimate of the average treatment effect we are insterested in. The interpretation is that employment in New Jersey rose by about 2.75 FTE due to the minimum wage increase. However, we cannot reject the hypothesis that the coefficient is zero due to different standard errors than those repoted in the paper.")