library(tidyverse)
library(haven)
library(stargazer)
library(broom)
library(purrr)
library(forcats)
library(viridisLite)
library(ggstance)
# By default, R uses polynomial contrasts for ordered factors in linear models
# options("contrasts")
# So make ordered factors use treatment contrasts instead
options(contrasts=rep("contr.treatment", 2))
df.crim <- readRDS("data/df_crim.rds") %>%
filter(year > 2002, year < 2016) %>%
mutate(cowcode.i = as.factor(cowcode), year.i = as.factor(year))
Our main questions: When external actors push for legal reforms, is it just a cheap response? or is there actual change? Does it matter whether domestic pressure changes domestic laws, or is it just paper compliance?
On p. 161 in Scorecard Diplomacy in “Is Criminalization Meaningful or Just Cheap Talk?”, we look just at averages. We can get better details than just averages.
TODO
Variables/data to get:
Modeling things:
- Model time since criminalization
- Can we think of another example where there has been external pressure (perhaps from a treaty) to implement reforms, and where we can consider implementing legislation.
- Is there a way to do mediation analysis? Is criminalization mediating the effects of the palermo protocol or of tier pressure — or a combination?
Other issues
- Partial vs. full criminalization
- Figure 6.8 from the book - look at two of the three Ps (not prosecution) as DVs in Cho’s models
- Also code if countries have an action plan or not - that might matter too - control for US effort (not the TIP score, but other measures of aid, like Wikileaks, USAID, number of trafficking NGOs in the country, etc.)
Run models
For now, we just add the degree of criminalization as a continuous variable (0–2) to the original Cho OLS models.
model1 <- lm(prot_prev ~ prot_prev_lag + crim.level_lag +
corruption + polity + female.leg.prop + wecon +
palermo.ratified + gdp.capita_log + us.aid.pct.gdp +
year.i + cowcode.i,
data = df.crim)
model2 <- lm(prevention ~ prevention_lag + crim.level_lag +
corruption + polity + female.leg.prop + wecon +
palermo.ratified + gdp.capita_log + us.aid.pct.gdp +
year.i + cowcode.i,
data = df.crim)
model3 <- lm(protection ~ protection_lag + crim.level_lag +
corruption + polity + female.leg.prop + wecon +
palermo.ratified + gdp.capita_log + us.aid.pct.gdp +
year.i + cowcode.i,
data = df.crim)
model4 <- lm(prot_prev ~ prot_prev_lag2 + crim.level_lag2 +
corruption + polity + female.leg.prop + wecon +
palermo.ratified + gdp.capita_log + us.aid.pct.gdp +
year.i + cowcode.i,
data = df.crim)
model5 <- lm(prevention ~ prevention_lag2 + crim.level_lag2 +
corruption + polity + female.leg.prop + wecon +
palermo.ratified + gdp.capita_log + us.aid.pct.gdp +
year.i + cowcode.i,
data = df.crim)
model6 <- lm(protection ~ protection_lag2 + crim.level_lag2 +
corruption + polity + female.leg.prop + wecon +
palermo.ratified + gdp.capita_log + us.aid.pct.gdp +
year.i + cowcode.i,
data = df.crim)
Preliminarily it looks like criminalization matters substantially. Moving from 0 to 1 (or 1 to 2) in the preceding year is associated with a 0.14 point increase in the protection + prevention indexes and a 0.1 point increase in the protection index. The effect is positive for prevention, but not significant.
models <- list(model1, model2, model3, model4, model5, model6)
num.models <- length(models)
var.labs <- c("Protection + prevention (t − 1)", "Prevention (t − 1)",
"Protection (t − 1)", "**Criminalization (t - 1)**",
"Protection + prevention (t − 2)", "Prevention (t − 2)",
"Protection (t − 2)", "**Criminalization (t - 2)**",
"Control of corruption", "Democracy",
"Women legislators (%)", "Women economic rights",
"Palermo Protocol ratified", "GDP per capita (log)",
"US aid (% of GDP)")
dep.var.labels <- c("Protection + Prevention", "Prevention", "Protection",
"Protection + Prevention", "Prevention", "Protection")
col.labs <- sprintf("(%s)", 1:num.models)
extra.lines <- list(c("Model type",
rep("OLS", num.models)),
c("Country fixed effects",
rep("Yes", num.models)),
c("Year fixed effects",
rep("Yes", num.models)))
title <- "Checking for the effect of criminalization"
stargazer(models,
type = "html", omit = c("cow", "Constant", "year"),
add.lines = extra.lines, title = title, covariate.labels = var.labs,
dep.var.labels = dep.var.labels, dep.var.caption = "",
keep.stat = c("n", "adj.rsq"),
model.numbers = FALSE, column.labels = col.labs,
model.names = FALSE, dep.var.labels.include = TRUE)
Checking for the effect of criminalization
|
|
Protection + Prevention
|
Prevention
|
Protection
|
Protection + Prevention
|
Prevention
|
Protection
|
|
(1)
|
(2)
|
(3)
|
(4)
|
(5)
|
(6)
|
|
Protection + prevention (t − 1)
|
0.330***
|
|
|
|
|
|
|
(0.029)
|
|
|
|
|
|
|
|
|
|
|
|
|
Prevention (t − 1)
|
|
0.255***
|
|
|
|
|
|
|
(0.030)
|
|
|
|
|
|
|
|
|
|
|
|
Protection (t − 1)
|
|
|
0.283***
|
|
|
|
|
|
|
(0.029)
|
|
|
|
|
|
|
|
|
|
|
Criminalization (t - 1)
|
0.138**
|
0.053
|
0.106***
|
|
|
|
|
(0.059)
|
(0.038)
|
(0.040)
|
|
|
|
|
|
|
|
|
|
|
Protection + prevention (t − 2)
|
|
|
|
0.040
|
|
|
|
|
|
|
(0.031)
|
|
|
|
|
|
|
|
|
|
Prevention (t − 2)
|
|
|
|
|
-0.058*
|
|
|
|
|
|
|
(0.032)
|
|
|
|
|
|
|
|
|
Protection (t − 2)
|
|
|
|
|
|
0.073**
|
|
|
|
|
|
|
(0.031)
|
|
|
|
|
|
|
|
Criminalization (t - 2)
|
|
|
|
0.145**
|
0.020
|
0.127***
|
|
|
|
|
(0.063)
|
(0.039)
|
(0.042)
|
|
|
|
|
|
|
|
Control of corruption
|
0.355*
|
0.261**
|
0.111
|
0.472**
|
0.408***
|
0.102
|
|
(0.202)
|
(0.130)
|
(0.137)
|
(0.220)
|
(0.138)
|
(0.146)
|
|
|
|
|
|
|
|
Democracy
|
-0.004
|
0.018
|
-0.024
|
-0.005
|
0.020
|
-0.026*
|
|
(0.021)
|
(0.014)
|
(0.014)
|
(0.023)
|
(0.014)
|
(0.015)
|
|
|
|
|
|
|
|
Women legislators (%)
|
-0.001
|
-0.001
|
0.0003
|
-0.002
|
-0.002
|
0.001
|
|
(0.003)
|
(0.002)
|
(0.002)
|
(0.004)
|
(0.002)
|
(0.002)
|
|
|
|
|
|
|
|
Women economic rights
|
0.006
|
0.073*
|
-0.072*
|
-0.002
|
0.081*
|
-0.087*
|
|
(0.063)
|
(0.040)
|
(0.043)
|
(0.067)
|
(0.042)
|
(0.045)
|
|
|
|
|
|
|
|
Palermo Protocol ratified
|
0.144
|
0.102
|
0.051
|
0.315***
|
0.167**
|
0.149*
|
|
(0.108)
|
(0.069)
|
(0.073)
|
(0.119)
|
(0.074)
|
(0.079)
|
|
|
|
|
|
|
|
GDP per capita (log)
|
0.663*
|
0.671***
|
0.025
|
0.720*
|
0.759***
|
0.022
|
|
(0.340)
|
(0.219)
|
(0.229)
|
(0.376)
|
(0.235)
|
(0.247)
|
|
|
|
|
|
|
|
US aid (% of GDP)
|
2.939
|
2.869
|
-0.359
|
-1.070
|
-0.894
|
-0.566
|
|
(3.930)
|
(2.527)
|
(2.262)
|
(3.553)
|
(2.221)
|
(2.365)
|
|
|
|
|
|
|
|
|
Model type
|
OLS
|
OLS
|
OLS
|
OLS
|
OLS
|
OLS
|
Country fixed effects
|
Yes
|
Yes
|
Yes
|
Yes
|
Yes
|
Yes
|
Year fixed effects
|
Yes
|
Yes
|
Yes
|
Yes
|
Yes
|
Yes
|
Observations
|
1,234
|
1,235
|
1,239
|
1,166
|
1,168
|
1,173
|
Adjusted R2
|
0.756
|
0.646
|
0.665
|
0.730
|
0.630
|
0.644
|
|
Note:
|
p<0.1; p<0.05; p<0.01
|
Estimating direct effects
Example using Fearon and Laitin 2003
# Panel-based lags (but tidyverse is way easier than this...)
pan.lag <- function(x, ind, lag = 1) {
unlist(tapply(x,ind, function(x) c(rep(NA, times = lag),x[-((length(x) - lag +1):length(x))])))
}
# Load and clean data
fearon <- read_dta("data/repdata.dta")
fearon_subset <- filter(fearon, onset < 4) %>%
mutate(instab2 = 1 * (abs(polity2l - pan.lag(polity2, ccode, 2)) > 3))
# Baseline model
baseline <- lm(onset ~ lmtnest + ncontig + Oil + ethfrac + relfrac,
data = fearon_subset)
# summary(baseline)
# Baseline model +
ptbias <- lm(onset ~ lmtnest + ncontig + Oil +
ethfrac + relfrac + instab2,
data = fearon_subset)
# summary(ptbias)
# First stage (to get effect of instability)
first <- lm(onset ~ warl + gdpenl + lpop + lmtnest +
ncontig + Oil + nwstate + instab + polity2l + ethfrac + relfrac,
data = fearon_subset)
# summary(first)
# Second stage (CDE of ethfrac without instability)
direct <- lm(I(onset - coef(first)["instab"] * instab) ~ lmtnest + ncontig +
Oil + ethfrac + relfrac,
data = fearon_subset)
# summary(direct)
coefs <- tribble(
~model_name, ~model,
"Baseline", baseline,
"With instability", ptbias,
"Fearon and Laitin", first,
"ACDE", direct) %>%
mutate(tidified = model %>% map(~ tidy(., conf.int = TRUE))) %>%
unnest(tidified)
to_plot <- coefs %>%
filter(term == "ethfrac") %>%
mutate(model_name = fct_rev(fct_inorder(model_name)))
ggplot(to_plot, aes(x = estimate, y = model_name, color = model_name)) +
geom_pointrangeh(aes(xmin = conf.low, xmax = conf.high)) +
geom_vline(xintercept = 0) +
scale_color_viridis_d(option = "magma", end = 0.9, guide = FALSE) +
labs(x = "Estimate", y = NULL) +
theme_light()
Our own average controlled direct effect estimation
If we want to do the same ACDE estimation, we have to distinguish between these types of variables:
- Pretreatment confounders
- Intermediate confounders
- Posttreatment variables
LS0tCnRpdGxlOiAiRWZmZWN0IG9mIGNyaW1pbmFsaXphdGlvbiIKZGF0ZTogImByIGZvcm1hdChTeXMudGltZSgpLCAnJUYnKWAiCmVkaXRvcl9vcHRpb25zOiAKICBjaHVua19vdXRwdXRfdHlwZTogY29uc29sZQotLS0KCmBgYHtyIHNldHVwLCBpbmNsdWRlPUZBTFNFfQprbml0cjo6b3B0c19jaHVuayRzZXQoZmlnLnJldGluYSA9IDIsCiAgICAgICAgICAgICAgICAgICAgICB0aWR5Lm9wdHM9bGlzdCh3aWR0aC5jdXRvZmYgPSAxMDApLCAgIyBGb3IgY29kZQogICAgICAgICAgICAgICAgICAgICAgb3B0aW9ucyh3aWR0aCA9IDEwMCkpICAjIEZvciBvdXRwdXQKYGBgCgpgYGB7ciBsb2FkLWxpYnJhcmllcywgbWVzc2FnZT1GQUxTRX0KbGlicmFyeSh0aWR5dmVyc2UpCmxpYnJhcnkoaGF2ZW4pCmxpYnJhcnkoc3RhcmdhemVyKQpsaWJyYXJ5KGJyb29tKQpsaWJyYXJ5K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b24gKHQg4oiSIDIpIiwgIlByZXZlbnRpb24gKHQg4oiSIDIpIiwgCiAgICAgICAgICAgICAgIlByb3RlY3Rpb24gKHQg4oiSIDIpIiwgIioqQ3JpbWluYWxpemF0aW9uICh0IC0gMikqKiIsCiAgICAgICAgICAgICAgIkNvbnRyb2wgb2YgY29ycnVwdGlvbiIsICJEZW1vY3JhY3kiLCAKICAgICAgICAgICAgICAiV29tZW4gbGVnaXNsYXRvcnMgKCUpIiwgIldvbWVuIGVjb25vbWljIHJpZ2h0cyIsCiAgICAgICAgICAgICAgIlBhbGVybW8gUHJvdG9jb2wgcmF0aWZpZWQiLCAiR0RQIHBlciBjYXBpdGEgKGxvZykiLCAKICAgICAgICAgICAgICAiVVMgYWlkICglIG9mIEdEUCkiKQoKZGVwLnZhci5sYWJlbHMgPC0gYygiUHJvdGVjdGlvbiArIFByZXZlbnRpb24iLCAiUHJldmVudGlvbiIsICJQcm90ZWN0aW9uIiwKICAgICAgICAgICAgICAgICAgICAiUHJvdGVjdGlvbiArIFByZXZlbnRpb24iLCAiUHJldmVudGlvbiIsICJQcm90ZWN0aW9uIikKCmNvbC5sYWJzIDwtIHNwcmludGYoIiglcykiLCAxOm51bS5tb2RlbHMpCgpleHRyYS5saW5lcyA8LSBsaXN0KGMoIk1vZGVsIHR5cGUiLAogICAgICAgICAgICAgICAgICAgICAgcmVwKCJPTFMiLCBudW0ubW9kZWxzKSksCiAgICAgICAgICAgICAgICAgICAgYygiQ291bnRyeSBmaXhlZCBlZmZlY3RzIiwKICAgICAgICAgICAgICAgICAgICAgIHJlcCgiWWVzIiwgbnVtLm1vZGVscykpLAogICAgICAgICAgICAgICAgICAgIGMoIlllYXIgZml4ZWQgZWZmZWN0cyIsCiAgICAgICAgICAgICAgICAgICAgICByZXAoIlllcyIsIG51bS5tb2RlbHMpKSkKCnRpdGxlIDwtICJDaGVja2luZyBmb3IgdGhlIGVmZmVjdCBvZiBjcmltaW5hbGl6YXRpb24iCgpzdGFyZ2F6Z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