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) t_test <- t.test(dat_NJ$FTE, dat_NJ$FTE2, var.equal = F) emp_mod <- lm(empl ~ D, data = reg_dat, subset = state == 1) # check that estimates and t-statistics coincide t_test <- t.test(dat_NJ$FTE, dat_NJ$FTE2, var.equal = F) emp_mod <- lm(empl ~ D, data = reg_dat, subset = state == 1) # estimates emp_mod$coef[2] diff(t_test$estimate) # t-statistics t_test$statistic coeftest(emp_mod, vcov. = vcovHC, type = "HC1")[2,3]