Q1.
set.seed(123)
n <- 100
T <- 20
treatment_year <- 10
year = rep(1:T, times = n)
treatment = round(runif(n*T,0,1))
U = rnorm(T*n,5,1)
outcome = ifelse(rep(1:T, times = n) > treatment_year & treatment==1, rnorm(T*n, mean = 2) + U, rnorm(T*n, mean=1) + U)
post = ifelse(year > treatment_year, 1, 0)
data <- data.frame(year, post, treatment, outcome)
(i)Generate a graph of the parallel trends between the treatment and control group.
data <- data %>%
mutate(group = ifelse(treatment == 1, "Treatment", "Control"))
mean_data <- data %>%
group_by(year, group) %>%
summarise(mean_outcome = mean(outcome, na.rm = TRUE))
## `summarise()` has grouped output by 'year'. You can override using the
## `.groups` argument.
ggplot(mean_data, aes(x = year, y = mean_outcome, color = group)) +
geom_line() +
geom_vline(xintercept = treatment_year, linetype = "dashed", color = "red") +
labs(x = "Year", y = "Mean Outcome", color = "Group") +
ggtitle("Parallel Trends between Treatment and Control Groups")
(ii)Run a DiD regression.
did_model <- lm(outcome ~ treatment * post + factor(year), data = data)
summary(did_model)
##
## Call:
## lm(formula = outcome ~ treatment * post + factor(year), data = data)
##
## Residuals:
## Min 1Q Median 3Q Max
## -4.6353 -0.9419 0.0071 0.9605 5.1058
##
## Coefficients: (1 not defined because of singularities)
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 6.0952069 0.1493650 40.807 < 2e-16 ***
## treatment -0.0731391 0.0895639 -0.817 0.414
## post 0.0719330 0.2086003 0.345 0.730
## factor(year)2 -0.1317490 0.1993636 -0.661 0.509
## factor(year)3 -0.2312631 0.1991704 -1.161 0.246
## factor(year)4 0.0952916 0.1991321 0.479 0.632
## factor(year)5 -0.2467377 0.1989709 -1.240 0.215
## factor(year)6 -0.1016204 0.1992127 -0.510 0.610
## factor(year)7 -0.0923460 0.1990979 -0.464 0.643
## factor(year)8 -0.1043657 0.1994219 -0.523 0.601
## factor(year)9 -0.0375486 0.1990979 -0.189 0.850
## factor(year)10 -0.1995079 0.1989689 -1.003 0.316
## factor(year)11 0.0014894 0.1992118 0.007 0.994
## factor(year)12 -0.1891109 0.1992118 -0.949 0.343
## factor(year)13 -0.1086835 0.1992118 -0.546 0.585
## factor(year)14 -0.0003991 0.1994824 -0.002 0.998
## factor(year)15 -0.2829322 0.1989870 -1.422 0.155
## factor(year)16 -0.1204599 0.1993080 -0.604 0.546
## factor(year)17 -0.0194800 0.1991696 -0.098 0.922
## factor(year)18 -0.2270702 0.1990010 -1.141 0.254
## factor(year)19 -0.1001388 0.1990191 -0.503 0.615
## factor(year)20 NA NA NA NA
## treatment:post 1.0228682 0.1265473 8.083 1.09e-15 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.407 on 1978 degrees of freedom
## Multiple R-squared: 0.09717, Adjusted R-squared: 0.08758
## F-statistic: 10.14 on 21 and 1978 DF, p-value: < 2.2e-16
(iii)Even without controlling for the unobserved confounder, where we about to find the ATE of the intervention? What is the ATE of the intervention?
Based on the provided data and code, the Average Treatment Effect (ATE) of the intervention can be found from the coefficient of the treatment * post interaction term in the DiD regression model.
Q2. Describe FE regression and how it can remove omitted variable bias. What is Two Way Fixed Effects (TWFE)? What is the relationship between TWFE and DiD?
FE regression controls for unobserved, time-invariant factors that may affect the outcome variable. This removes omitted variable bias. Two-Way Fixed Effects (TWFE) extends FE regression by including fixed effects for two dimensions, typically entities and time periods. TWFE is closely related to the Difference-in-Differences (DiD) approach. DiD can be considered a special case of TWFE where the treatment is binary and interacted with time fixed effects. TWFE is more flexible, handling continuous treatments and multiple time periods, while DiD is designed for binary treatments and two time periods (before and after). Both TWFE and DiD control for unobserved time-invariant characteristics and time trends, but TWFE can be applied more broadly.
Q3. Describe the method of synthetic controls.
The synthetic control method is a approach for estimating causal effects, especially in comparative case studies with a small number of treated units. It constructs a synthetic control unit as a weighted combination of untreated units that best reproduces the characteristics and outcome trajectory of the treated unit prior to the intervention. The weights are chosen to minimize the pre-intervention differences between the treated unit and its synthetic counterpart. After the intervention, the post-intervention outcome trajectory of the synthetic control is used as an estimate of the counterfactual - what would have happened to the treated unit if it had not received the treatment. The causal effect is then calculated as the difference between the actual outcome of the treated unit and the outcome of its synthetic control.
Q4.
n <- 500
running_variable <- runif(n, min = 0, max = 10)
cutoff <- 5
treatment <- ifelse(running_variable >= cutoff, 1, 0)
outcome <- ifelse(running_variable >= cutoff, 2 + 0.5 * (running_variable - cutoff) - 0.1 * (running_variable - cutoff)^2 + rnorm(n, mean=0, sd=1), -2 +0.5 * (running_variable - cutoff) - 0.1 * (running_variable - cutoff)^2 + rnorm(n, mean=0, sd=1))
data <- data.frame(Running_variable = running_variable, Treatment = treatment, Outcome = outcome)
plot(data$Running_variable, data$Outcome, col = ifelse(data$Treatment == 1, "red", "blue"), xlab = "Running Variable", ylab = "Outcome", main = "Simulated Data for RDD")
abline(v = cutoff, lty = 2, col = "green")
legend("topright", legend = c("Treatment = 0", "Treatment = 1", "Cutoff"), col=c("blue", "red", "green"), lty = c(1,1,2))
(i)Fit and plot regression lines on either side of the cutoff
reg_treat <- lm(Outcome ~ Running_variable, data = data[data$Treatment == 1, ])
reg_control <- lm(Outcome ~ Running_variable, data = data[data$Treatment == 0, ])
plot(data$Running_variable, data$Outcome, col = ifelse(data$Treatment == 1, "red", "blue"), xlab = "Running Variable", ylab = "Outcome", main = "Simulated Data for RDD")
abline(v = cutoff, lty = 2, col = "green")
abline(reg_treat, col = "red", lwd = 2)
abline(reg_control, col = "blue", lwd = 2)
legend("topright", legend = c("Treatment = 0", "Treatment = 1", "Cutoff", "Treatment Regression Line", "Control Regression Line"), col = c("blue", "red", "green", "red", "blue"), lty = c(1, 1, 2, 1, 1), lwd = c(1, 1, 1, 2, 2))
(ii)What is the ATE?
the true functional form of the outcome for the treatment group (running_variable >= cutoff) is:2 + 0.5(running_variable - cutoff) - 0.1(running_variable - cutoff)^2
the control group (running_variable < cutoff):-2 + 0.5(running_variable - cutoff) - 0.1(running_variable - cutoff)^2
At the cutoff point (running_variable = cutoff = 5), ATE = 2 - (-2) = 4
(iii)Is this a fuzzy RDD or a sharp RDD? Why does fuzzy RRD obtain the LATE?
This is a sharp RDD because the treatment assignment is deterministic based on the running variable and the cutoff value. In a fuzzy RDD, the estimate obtained is the LATE because of the presence of always-takers and never-takers, and the focus is on the causal effect for the compliers.