Load the packages we want.
### Quietly load all packages needed
### insert your code here
library(dplyr)
library(readxl)
library(knitr)
library(tidyverse)
library(ggplot2)
library(lmtest)
library(sandwich)
Load the data here
### do not change anything in {}
### r work for answering question goes here
new_directory <- "C:/Users/havil/Documents/1a Homework 1 Clinic Sales Case Study"
setwd(new_directory)
clusterdata = read.csv("cluster.csv")
Calculate the average treatment effect on sales and the 95% confidence interval on that average under the assumption that you can treat each of the 200,000 observations in the data as independent. (That is, just analyze this the way you have analyzed other data so far in this course).
### do not change anything in {}
### r work for answering question goes here
outcome_table = clusterdata %>% group_by(treatment) %>%
summarise(N=n(), m = mean(sale), sd = sd(sale)) %>%
mutate( se = sd / sqrt(N),
lb = m - 1.96*se, ub = m + 1.96*se
)
ate_table = outcome_table %>%
mutate(
ate = m - m[1], ate_se = sqrt(se^2 + se[1]^2), ate_lb = ate - 1.96*ate_se, ate_ub = ate + 1.96*ate_se,
)
ate_table = ate_table %>%
select( treatment,ate, ate_lb, ate_ub,
) %>%
filter(treatment != 0)
kable(ate_table, digits = 2)
| treatment | ate | ate_lb | ate_ub |
|---|---|---|---|
| 1 | 3.6 | 3.42 | 3.78 |
Q1
We have to make the assumption that the cluster labels do not mean anything, excluability, no defiers, and that there is random assignment to treatment.
There is an average treatment effect of 3.6 that has Confidence Interval between 3.42-3.78
### do not change anything in {}
### r work for answering question goes here
outcome_table = clusterdata %>% group_by(treatment, store_id) %>%
summarise(N=n(),
m = mean(sale), sd = sd(sale)
) %>%
mutate(
se = sd / sqrt(N), lb = m - 1.96*se, ub = m + 1.96*se )
## `summarise()` has grouped output by 'treatment'. You can override using the
## `.groups` argument.
cluster_table = outcome_table %>% group_by(treatment) %>%
summarise(N=n(), m_cluster = mean(m),
sd_cluster = sd(sd)
) %>%
mutate(
se_cluster = sd_cluster / sqrt(N),
lb_cluster = m_cluster - 1.96*se_cluster,
ub_cluster = m_cluster + 1.96*se_cluster)
ate_table = cluster_table %>%
mutate(
ate_cluster = m_cluster - m_cluster[1], ate_se_cluster = sqrt(se_cluster^2 + se_cluster[1]^2), ate_lb_cluster = ate_cluster - 1.96*ate_se_cluster,
ate_ub_cluster = ate_cluster + 1.96*ate_se_cluster,)
ate_table = ate_table %>%
select( treatment, ate_cluster, ate_lb_cluster, ate_ub_cluster,
) %>% filter(treatment != 0)
kable(cluster_table, digits = 2)
There is an average treatment effect of 3.6 that has a 95% Confidence Interval between 3.51-3.69
There are no changes in the Average Treatment Effect, which stayed at 3.6. However, the CI became smaller as can be seen in the comparison 3.42-3.78 & 3.51-3.69
Load the data here
### do not change anything in {}
### r work for answering question goes here
new_directory <- "C:/Users/havil/Documents/1a Homework 1 Clinic Sales Case Study"
setwd(new_directory)
fludata = read.csv("flu_rct_2023.csv")
### do not change anything in {}
### r work for answering question goes here
fraction_table = fludata %>% group_by(treatment) %>%
summarise(N=n(), fraction = mean(quiz))
kable(fraction_table, digits = 2)
| treatment | N | fraction |
|---|---|---|
| 0 | 162 | 0.00 |
| 1 | 161 | 0.32 |
| 2 | 177 | 0.69 |
In treatment 0 zero people took the quiz.
In treatment 1 0.32 people took the quiz.
In treatment 2 0.69 people took the quiz.
Your boss, Pat, after seeing these statistics says to you: “Don’t we want to look at what share of people got the shot among the ones who took the quiz in the treatment groups?” What do you say to Pat?
Sure! This could tell us that if letting people know about the quiz would lead to more shots from informed employees.
What is the Intention to Treat estimate of the treatment effect for each treatment relative to control?
### do not change anything in {}
### r work for answering question goes here
ITT_table = fludata %>% group_by(treatment) %>% summarise(N=n(), flu = mean(flu_shot), quiz = mean(quiz)) %>%
mutate( ITT_1 = flu[2] - flu[1], ITT_2 = flu[3] - flu[1]
) %>%
filter(treatment != 0)
kable(ITT_table, digits = 2)
| treatment | N | flu | quiz | ITT_1 | ITT_2 |
|---|---|---|---|---|---|
| 1 | 161 | 0.58 | 0.32 | 0.08 | 0.19 |
| 2 | 177 | 0.69 | 0.69 | 0.08 | 0.19 |
Intention to Treat estimate of the treatment effect for each treatment is 0.08 for treatment 1 & and 0.19 for treatment 2.
In order for a Treatment on the Treated estimate to be valid, we have to believe that the only way that offering a treatment could affect behavior is through the person actually taking up the treatment (not just learning about it). Briefly discuss why that assumption might not be right in this setting.
It is assuming excludability and not taking into account the indirect channels that could have had effects. Some examples of this would would be the Spillover Effects, and Selction Bias.
Setting aside any concern from question 7, find the TOT for effect of survey on flu shot, comparing Treatment 1 to control? What about comparing Treatment 2 to control? What about comparing Treatment 2 to Treatment 1? [Note: this third question is not exactly something we have covered in class. Asking you to extend the logic of what we have done. ]
### do not change anything in {}
### r work for answering question goes here
TOT_table = fludata %>% group_by(treatment) %>%
summarise(N=n(),
flu = mean(flu_shot), quiz = mean(quiz) ) %>%
mutate(TOT_1 = (flu[2] - flu[1])/quiz, TOT_2 = (flu[3] - flu[1])/quiz
) %>% filter(treatment != 0)
kable(TOT_table, digits = 2)
| treatment | N | flu | quiz | TOT_1 | TOT_2 |
|---|---|---|---|---|---|
| 1 | 161 | 0.58 | 0.32 | 0.25 | 0.60 |
| 2 | 177 | 0.69 | 0.69 | 0.11 | 0.27 |
TOT for treatment 1 is 0.25 and 0.27 for treatment 2. TOT comparison for 1 & 2 is .6
Briefly give a conjecture (i.e., a guess/hypothesis) about what could be driving the difference in the Treatment on the Treated effects between Treatment 1 and Treatment 2.
Visits from HR could have influenced this indirectly because it would make the flu shot seem like a company mandate.
Did you use generative AI? If so, please explain how.
No