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) # set up the data for regression analysis # set up the data for regression analysis 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))) ex() %>% check_predefined_objects(c("dat", "dat_NJ", "dat_PA")) ex() %>% check_object("reg_dat", undefined_msg = "Make sure to not remove `reg_dat`!") %>% { check_column(., "id", col_missing_msg = "Have you added the column `id` to `reg_dat`?") %>% check_equal(incorrect_msg = "Have you correctly generated the column `id` based on `dat$sheet`?") check_column(., "chain", col_missing_msg = "Have you added the column `chain` to `reg_dat`?") %>% check_equal(incorrect_msg = "Have you correctly generated the column `chain` using `dat$chain`?") check_column(., "state", col_missing_msg = "Have you added the column `state` to `reg_dat`?") %>% check_equal(incorrect_msg = "Have you correctly generated the column `state` using `dat$state`?") check_column(., "empl", col_missing_msg = "Have you added the column `empl` to `reg_dat`?") %>% check_equal(incorrect_msg = "Have you correctly generated the column `empl` using `dat$FTE` and `dat$FTE?`?") check_column(., "D", col_missing_msg = "Have you added the column `D` to `reg_dat`?") %>% check_equal(incorrect_msg = "Have you correctly generated the column `D`? Note that this column must contain only 0s and 1s!") } success_msg(msg = "Nicely done!")