Skip to content

Commit

Permalink
Merge pull request #7 from be-green/hotfix/line-up-castle-code
Browse files Browse the repository at this point in the history
Update castle scripts
  • Loading branch information
scunning1975 authored Apr 18, 2020
2 parents 18f6601 + 22ea8f5 commit 6bd458a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 27 deletions.
24 changes: 5 additions & 19 deletions programs/castle_1.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,7 @@ xvar <- c(

law <- c("cdl")

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

formula2 <- as.formula(
dd_formula <- as.formula(
paste("l_homicide ~ ",
paste(
paste(xvar, collapse = " + "),
Expand All @@ -82,10 +70,8 @@ formula2 <- as.formula(
)
)

#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)
dd_reg <- felm(dd_formula, weights = castle$popwt, data = castle)
summary(dd_reg)


6 changes: 3 additions & 3 deletions programs/castle_2.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ castle <- castle %>%
lag5 = case_when(time_til == 5 ~ 1, TRUE ~ 0)
)

formula3 <- as.formula(
event_study_formula <- as.formula(
paste("l_homicide ~ + ",
paste(
paste(region, collapse = " + "),
Expand All @@ -29,5 +29,5 @@ formula3 <- as.formula(
),
)

reg3 <- felm(formula3, weights = castle$popwt, data = castle)
summary(reg3)
event_study_reg <- felm(event_study_formula, weights = castle$popwt, data = castle)
summary(event_study_reg)
4 changes: 2 additions & 2 deletions programs/castle_3.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ plot_order <- c("lead9", "lead8", "lead7",
# from the regression, label them accordingly
# add a zero'th lag for plotting purposes
leadslags_plot <- tibble(
sd = c(reg3$cse[plot_order], 0),
mean = c(coef(reg3)[plot_order], 0),
sd = c(event_study_reg$cse[plot_order], 0),
mean = c(coef(event_study_reg)[plot_order], 0),
label = c(-9,-8,-7,-6, -5, -4, -3, -2, -1, 1,2,3,4,5, 0)
)

Expand Down
6 changes: 3 additions & 3 deletions programs/castle_5.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ bacon_plot <- ggplot(data = df_bacon) +
bacon_plot

# create formula
formula4 <- as.formula(
bacon_dd_formula <- as.formula(
'l_homicide ~ post | year + sid | 0 | sid')

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

# Note that the estimate from earlier equals the
# coefficient on post
Expand Down

0 comments on commit 6bd458a

Please sign in to comment.