Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/scunning1975/mixtape
Browse files Browse the repository at this point in the history
  • Loading branch information
scunning1975 committed Jan 2, 2022
2 parents 6c8ca0f + 77e3de4 commit 2b8da22
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 17 deletions.
3 changes: 3 additions & 0 deletions Do/bail.do
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ ivregress 2sls guilt (jail3= $judge_pre) $control2, robust first
ivregress 2sls guilt (jail3= $judge_pre) possess robbery DUI1st drugSell aggAss $demo $prior $off $control2 , robust first

* JIVE main results
* jive can be installed using: net from https://www.stata-journal.com/software/sj6-3/
* net install st0108

* minimum controls
jive guilt (jail3= $judge_pre) $control2, robust
* maximum controls
Expand Down
21 changes: 20 additions & 1 deletion R/castle_3.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ leadslags_plot %>%
ggplot(aes(x = label, y = mean,
ymin = mean-1.96*sd,
ymax = mean+1.96*sd)) +
geom_hline(yintercept = 0.035169444, color = "red") +
geom_hline(yintercept = 0.0769, color = "red") +
geom_pointrange() +
theme_minimal() +
xlab("Years before and after castle doctrine expansion") +
Expand All @@ -34,4 +34,23 @@ leadslags_plot %>%
linetype = "dashed")


# This version includes
# an interval that traces the confidence intervals
# of your coefficients
leadslags_plot %>%
ggplot(aes(x = label, y = mean,
ymin = mean-1.96*sd,
ymax = mean+1.96*sd)) +
# this creates a red horizontal line
geom_hline(yintercept = 0.0769, color = "red") +
geom_line() +
geom_point() +
geom_ribbon(alpha = 0.2) +
theme_minimal() +
# Important to have informative axes labels!
xlab("Years before and after castle doctrine expansion") +
ylab("log(Homicide Rate)") +
geom_hline(yintercept = 0) +
geom_vline(xintercept = 0)


2 changes: 1 addition & 1 deletion R/castle_4.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ leadslags_plot %>%
ymin = mean-1.96*sd,
ymax = mean+1.96*sd)) +
# this creates a red horizontal line
geom_hline(yintercept = 0.035169444, color = "red") +
geom_hline(yintercept = 0.0769, color = "red") +
geom_line() +
geom_point() +
geom_ribbon(alpha = 0.2) +
Expand Down
2 changes: 1 addition & 1 deletion R/sasp.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ balanced_sasp <- balanced_sasp %>% mutate(
demean_asian_cl = asian_cl - ave(asian_cl, id),
demean_black_cl = black_cl - ave(black_cl, id),
demean_hispanic_cl = hispanic_cl - ave(hispanic_cl, id),
demean_othrace_cl = othrace_cl - ave(lnw, id),
demean_othrace_cl = othrace_cl - ave(othrace_cl, id),
demean_hot = hot - ave(hot, id),
demean_massage_cl = massage_cl - ave(massage_cl, id)
)
Expand Down
7 changes: 4 additions & 3 deletions R/thornton_ri.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ tb <- NULL

permuteHIV <- function(df, random = TRUE){
tb <- df
first_half <- ceiling(nrow(tb)/2)
second_half <- nrow(tb) - first_half
# Number of treated in dataset
n_treated <- 2222
n_control <- nrow(tb) - n_treated

if(random == TRUE){
tb <- tb %>%
sample_frac(1) %>%
mutate(any = c(rep(1, first_half), rep(0, second_half)))
mutate(any = c(rep(1, n_treated), rep(0, n_control)))
}

te1 <- tb %>%
Expand Down
8 changes: 3 additions & 5 deletions python/castle_3.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,12 @@ def read_data(file):
leadslags_plot['lb'] = leadslags_plot['mean'] - leadslags_plot['sd']*1.96
leadslags_plot['ub'] = leadslags_plot['mean'] + leadslags_plot['sd']*1.96

# This version has a point-range at each
# estimated lead or lag
# comes down to stylistic preference at the
# end of the day!
# This version has a point-range at each estimated lead or lag
# comes down to stylistic preference at the end of the day!
p.ggplot(leadslags_plot, p.aes(x = 'label', y = 'mean',
ymin = 'lb',
ymax = 'ub')) +\
p.geom_hline(yintercept = 0.035169444, color = "red") +\
p.geom_hline(yintercept = 0.0769, color = "red") +\
p.geom_pointrange() +\
p.theme_minimal() +\
p.xlab("Years before and after castle doctrine expansion") +\
Expand Down
17 changes: 16 additions & 1 deletion python/castle_4.py
Original file line number Diff line number Diff line change
@@ -1 +1,16 @@
# Missing python script
# This version has a point-range at each estimated lead or lag
# comes down to stylistic preference at the end of the day!
p.ggplot(leadslags_plot, p.aes(x = 'label', y = 'mean',
ymin = 'lb',
ymax = 'ub')) +\
p.geom_hline(yintercept = 0.0769, color = "red") +\
p.geom_line() +\
p.geom_point() +\
p.geom_ribbon(alpha = 0.2) +\
p.theme_minimal() +\
p.xlab("Years before and after castle doctrine expansion") +\
p.ylab("log(Homicide Rate)") +\
p.geom_hline(yintercept = 0,
linetype = "dashed") +\
p.geom_vline(xintercept = 0,
linetype = "dashed")
4 changes: 2 additions & 2 deletions python/nsw_pscore.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ def read_data(file):
nsw_dw_cpscontrol = read_data('cps_mixtape.dta')

nsw_dw_cpscontrol = pd.concat((nsw_dw_cpscontrol, nsw_dw))
nsw_dw_cpscontrol[['u74', 'u75']] = 0
nsw_dw_cpscontrol['u74'], nsw_dw_cpscontrol['u75'] = 0, 0
nsw_dw_cpscontrol.loc[nsw_dw_cpscontrol.re74==0, 'u74'] = 1
nsw_dw_cpscontrol.loc[nsw_dw_cpscontrol.re75==0, 'u75'] = 1
# estimating propensity score
logit_nsw = smf.glm(formula="""treat ~ age + age**2 + age**3 + educ + educ**2 +
logit_nsw = smf.glm(formula="""treat ~ age + I(age**2) + I(age**3) + educ + I(educ**2) +
marr + nodegree + black + hisp + re74 + re75 + u74 + u75 + educ*re74""",
family=sm.families.Binomial(),
data=nsw_dw_cpscontrol).fit()
Expand Down
6 changes: 3 additions & 3 deletions python/thornton_ri.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ def read_data(file):

def permuteHIV(df, random = True):
tb = df.copy()
first_half = np.ceil(tb.shape[0] / 2)
second_half = tb.shape[0] - first_half
n_treated = 2222
n_control = tb.shape[0] - n_treated
if random:
tb = tb.sample(frac=1)
tb['any'] = np.concatenate((np.repeat(1, first_half), np.repeat(0, second_half)))
tb['any'] = np.concatenate((np.repeat(1, n_treated), np.repeat(0, n_control)))

te1 = tb[tb['any']==1]['got'].mean()
te0 = tb[tb['any']==0]['got'].mean()
Expand Down

0 comments on commit 2b8da22

Please sign in to comment.