Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Castle fixes #2

Merged
merged 2 commits into from
Apr 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions programs/castle_1.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,26 +61,31 @@ law <- c("cdl")

#--- Generating the formula
formula1 <- as.formula(
paste("l_homicide ~ post + ",
paste("l_homicide ~ ",
paste(
paste(xvar, collapse = " + "),
paste(region, collapse = " + "),
paste(lintrend, collapse = " + "),
paste(law, collapse = " + "), sep = " + "),
"| year | 0 | sid"
"| year + sid | 0 | sid"
)
)

formula2 <- as.formula(
paste("l_homicide ~ post + ",
paste("l_homicide ~ ",
paste(
paste(xvar, collapse = " + "),
paste(region, collapse = " + "),
paste(lintrend, collapse = " + "),
paste("post", collapse = " + "), sep = " + "),
"| year | 0 | sid"
"| year + sid | 0 | sid"
)
)

#Fixed effect regression using cdl as treatment variable
reg1 <- felm(formula1, weights = castle$popwt, data = castle)
summary(reg1)

#Fixed effect regression using post as treatment variable
reg2 <- felm(formula2, weights = castle$popwt, data = castle)
summary(reg2)
1 change: 1 addition & 0 deletions programs/castle_2.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ formula3 <- as.formula(
)

reg3 <- felm(formula3, weights = castle$popwt, data = castle)
summary(reg3)
44 changes: 28 additions & 16 deletions programs/castle_5.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,37 @@ df_bacon <- bacon(l_homicide ~ post,
data = castle, id_var = "state",
time_var = "year")

summary(df_bacon)
# Diff-in-diff estimate is the weighted average of
# individual 2x2 estimates
dd_estimate <- sum(df_bacon$estimate*df_bacon$weight)

# 2x2 Decomposition Plot
bacon_plot <- ggplot(data = df_bacon) +
geom_point(aes(x = weight, y = estimate,
color = type, shape = type), size = 2) +
xlab("Weight") +
ylab("2x2 DD Estimate") +
geom_hline(yintercept = dd_estimate, color = "red") +
theme_minimal() +
theme(
legend.title = element_blank(),
legend.background = element_rect(
fill="white", linetype="solid"),
legend.justification=c(1,1),
legend.position=c(1,1)
)

bacon_plot

# create formula
# drop one additional region variable due to colinearity
formula <- as.formula(
paste("l_homicide ~ post + lead9 + lead8 + lead7 + ",
"lead6 + lead5 + lead4 + lead3 + lead2 + lead1 + ",
"lag1 + lag2 + lag3 + lag4 + lag5 + ",
paste(
paste(xvar, collapse = " + "),
paste(subset(region, region != 'r20003'),
collapse = " + "),
paste(lintrend, collapse = " + "), sep = " + "),
"| year + sid"
)
)
formula4 <- as.formula(
'l_homicide ~ post | year + sid | 0 | sid')

reg <- felm(formula = formula, data = castle)
summary(reg)
# Simple diff-in-diff regression
reg4 <- felm(formula = formula4, data = castle)
summary(reg4)

# Note that the estimate from earlier equals the
# coefficient on post
dd_estimate