#######
#######
####### Replication files for Do Women Officers Police Differently? Evidence from Traffic Stops
####### This file produces the tables and figures seen in the paper and appendix.
####### Last Updated: Jan. 2021
#######
#######

###
### 1. Setting up the space. 
###

# Setting the working directory:
setwd("~/Desktop/PinkPolicing/AJPS_ReplicationFiles")

# Installing the needed libraries:
#install.packages("pscl",dependencies = T)
#install.packages("ggplot2",dependencies = T)
#install.packages("texreg",dependencies = T)
#install.packages("readr",dependencies = T)
#install.packages("arm",dependencies = T)

# Opening up those libraries:
library(ggplot2)
library(texreg)
## Version:  1.37.5
## Date:     2020-06-17
## Author:   Philip Leifeld (University of Essex)
## 
## Consider submitting praise using the praise or praise_interactive functions.
## Please cite the JSS article in your publications -- see citation("texreg").
library(readr)
library(pscl)
## Classes and Methods for R developed in the
## Political Science Computational Laboratory
## Department of Political Science
## Stanford University
## Simon Jackman
## hurdle and zeroinfl functions by Achim Zeileis
library(arm)
## Loading required package: MASS
## Loading required package: Matrix
## Loading required package: lme4
## 
## arm (Version 1.11-2, built: 2020-7-27)
## Working directory is /Users/kelseyshoub/Desktop/PinkPolicing/AJPS_ReplicationFiles
###
### 2. Body of the Paper
###

# Clearing the workspace + reading in data bit by bit to produce each table and figure. 
rm(list = ls())

# Loading in the Data
load("Data/NorthCarolina.RData")
load("Data/FloridaLarge.RData")
load("Data/FloridaSmall.RData")
cmpd.employee = read_csv("Data/CMPD_Employee_Demographics.csv")
## 
## ── Column specification ──────────────────────────────────────────────────────
## cols(
##   JOB_TITLE = col_character(),
##   Years_Of_Service = col_double(),
##   Age = col_double(),
##   Gender = col_character(),
##   Race = col_character(),
##   ObjectID = col_double()
## )
# Number of stops and searches by sex:
dim(fl)
## [1] 4842950      52
dim(nc)
## [1] 218158     32
table(fl$search_occur)
## 
##       0       1 
## 4391272   17356
table(nc$search)
## 
##      0      1 
## 207714  10444
prop.table(table(fl$search_occur))
## 
##           0           1 
## 0.996063174 0.003936826
prop.table(table(nc$search))
## 
##          0          1 
## 0.95212644 0.04787356
table(fl$of_gender)
## 
##       0       1 
## 3870641  291604
table(nc$of_gender)
## 
##      0      1 
## 199234  18924
table(fl$of_gender,fl$search_occur)
##    
##           0       1
##   0 3843369   16422
##   1  290820     272
table(nc$of_gender,nc$search)
##    
##          0      1
##   0 189611   9623
##   1  18103    821
prop.table(table(fl$of_gender,fl$search_occur),1)
##    
##                0            1
##   0 0.9957453655 0.0042546345
##   1 0.9990655875 0.0009344125
prop.table(table(nc$of_gender,nc$search),1)
##    
##              0          1
##   0 0.95170001 0.04829999
##   1 0.95661594 0.04338406
table(fl$of_gender,fl$contra)
##    
##           0       1
##   0 3865730    4911
##   1  291491     113
# Number of officers by sex in FL
length(unique(fl$officer_id_hash))
## [1] 2708
length(unique(fl$officer_id_hash[fl$of_gender==0]))
## [1] 1916
length(unique(fl$officer_id_hash[fl$of_gender==1]))
## [1] 244
length(unique(fl$officer_id_hash[fl$officer_exclude==0]))
## [1] 2338
length(unique(fl$officer_id_hash[fl$of_gender==0&fl$officer_exclude==0]))
## [1] 1910
length(unique(fl$officer_id_hash[fl$of_gender==1&fl$officer_exclude==0]))
## [1] 244
table(cmpd.employee$JOB_TITLE[cmpd.employee$JOB_TITLE=="Police Officer"])
## 
## Police Officer 
##           1540
sum(table(cmpd.employee$Gender[cmpd.employee$JOB_TITLE=="Police Officer"]))
## [1] 1540
table(fl$year)
## 
##   2010   2011   2012   2013   2014   2015 
## 675487 870349 748026 830791 922008 796289
(table(fl$of_gender)/c(length(unique(fl$officer_id_hash[fl$of_gender==0&fl$officer_exclude==0])),length(unique(fl$officer_id_hash[fl$of_gender==1&fl$officer_exclude==0]))))/6
## 
##        0        1 
## 337.7523 199.1831
avg.stops = aggregate(fl$year,by=list(fl$officer_id_hash,fl$year,fl$of_gender),length)
summary(avg.stops)
##    Group.1            Group.2             Group.3             x         
##  Length:9319        Length:9319        Min.   :0.0000   Min.   :   1.0  
##  Class :character   Class :character   1st Qu.:0.0000   1st Qu.: 125.0  
##  Mode  :character   Mode  :character   Median :0.0000   Median : 359.0  
##                                        Mean   :0.1062   Mean   : 446.6  
##                                        3rd Qu.:0.0000   3rd Qu.: 649.0  
##                                        Max.   :1.0000   Max.   :5299.0
mean(avg.stops$x)
## [1] 446.6407
median(avg.stops$x[avg.stops$Group.3==0])
## [1] 380
median(avg.stops$x[avg.stops$Group.3==1])
## [1] 202.5
prop.table(table(fl$investigatory[fl$of_gender==0]))
## 
##         0         1 
## 0.4649428 0.5350572
prop.table(table(fl$investigatory[fl$of_gender==1]))
## 
##         0         1 
## 0.4334131 0.5665869
table(nc$of_gender[nc$year==2019])[2:1]/table(cmpd.employee$Gender[cmpd.employee$JOB_TITLE=="Police Officer"])
## 
##        1        0 
## 33.13750 68.11154
# Excluding Cases:
dim(nc)
## [1] 218158     32
dim(nc)-dim(nc[!is.na(nc$search),])
## [1] 0 0
dim(fl)
## [1] 4842950      52
dim(fl)-dim(fl[!is.na(fl$search_occur),])
## [1] 434322      0
(dim(fl[!is.na(fl$search_occur),])-dim(fl.sm))+table(fl.sm$officer_exclude)[2]
## [1] 1695594   18170
table(fl.sm$county_include)
## 
##       0       1 
##     556 2730648
# Table 1
tab1 = data.frame("Department"=c("Charlotte PD (NC)",
                                 "Male Officers","Female Officers",
                                 "Florida Highwar Patrol",
                                 "Male Officers","Female Officers"),
                  "Type"=c("Municipal","","","Statewide","",""),
                  "Years"=c("2016-2017","","",
                            "2010-2015","",""),
                  "Stops"=c(dim(nc)[1],table(nc$of_gender),
                            dim(fl[!is.na(fl$search_occur),])[1],
                            table(fl$of_gender[!is.na(fl$search_occur)])),
                  "Searches"=c(table(nc$search)[2],table(nc$of_gender,nc$search)[,2],
                               table(fl$search_occur)[2],
                               table(fl$of_gender,fl$search_occur)[,2]),
                  "Search Rate"=c(table(nc$search)[2]/dim(nc)[1],
                                  table(nc$of_gender,nc$search)[,2]/table(nc$of_gender),
                                  table(fl$search_occur)[2]/dim(fl[!is.na(fl$search_occur),])[1],
                                  table(fl$of_gender,fl$search_occur)[,2]/
                                    table(fl$of_gender[!is.na(fl$search_occur)])))
tab1 = rbind(tab1,
             c("Total","","",
               sum(tab1[c(1,4),4]),sum(tab1[c(1,4),5]),
               sum(tab1[c(1,4),5])/sum(tab1[c(1,4),4])))
tab1
##               Department      Type     Years   Stops Searches
## 1      Charlotte PD (NC) Municipal 2016-2017  218158    10444
## 2          Male Officers                      199234     9623
## 3        Female Officers                       18924      821
## 4 Florida Highwar Patrol Statewide 2010-2015 4408628    17356
## 5          Male Officers                     3859791    16422
## 6        Female Officers                      291092      272
## 7                  Total                     4626786    27800
##            Search.Rate
## 1   0.0478735595302487
## 2    0.048299988957708
## 3   0.0433840625660537
## 4   0.0039368256972464
## 5  0.00425463451259408
## 6 0.000934412488148077
## 7  0.00600849055910518
# Figure 1
load("Data/Fig1_Data.RData")
png("Figures/Fig1_PredProb.png",
    750,519)
ggplot(data = search.df, aes(x=Department,y=Rate,fill=Gender)) + 
  geom_bar(stat="identity", position=position_dodge()) + 
  ylab("Search Rate") +
  theme_bw(base_size=15)+
  theme(legend.position = "bottom") +
  labs(fill="Officer Sex")+
  scale_fill_grey(start = 0.25, end = .75) 
dev.off()
## quartz_off_screen 
##                 2
prop.test(table(fl$of_gender,fl$search_occur))
## 
##  2-sample test for equality of proportions with continuity correction
## 
## data:  table(fl$of_gender, fl$search_occur)
## X-squared = 744.11, df = 1, p-value < 2.2e-16
## alternative hypothesis: two.sided
## 95 percent confidence interval:
##  -0.003450662 -0.003189782
## sample estimates:
##    prop 1    prop 2 
## 0.9957454 0.9990656
prop.test(table(nc$of_gender,nc$search))
## 
##  2-sample test for equality of proportions with continuity correction
## 
## data:  table(nc$of_gender, nc$search)
## X-squared = 9.0552, df = 1, p-value = 0.002619
## alternative hypothesis: two.sided
## 95 percent confidence interval:
##  -0.007996240 -0.001835613
## sample estimates:
##    prop 1    prop 2 
## 0.9517000 0.9566159
# Table 2
load("Data/FLSearch_Sm_OLS.RData")
load("Data/FLSearch_OLS.RData")
load("Data/NCSearch_Sm_OLS.RData")
load("Data/NCSearch_OLS.RData")
screenreg(list(nc.search,fl.search),
          stars=c(0.01,0.05),
          custom.coef.map = list("(Intercept)"="(Intercept)",
                                 "factor(of_gender)1"="Female Officer",
                                 "factor(of_race)1"="Black Officer",
                                 "factor(race_gender)1"="White Female",
                                 "factor(race_gender)2"="Black Male",
                                 "factor(race_gender)3"="Black Female",
                                 "factor(race_gender)4"="Latino Male",
                                 "factor(race_gender)5"="Latina Female",
                                 "investigatory" = "Investigatory Stop Purpose"),
          custom.model.names = c("(1) NC Search",
                                 "(2) FL Search"),
          digits=4)
## 
## ===========================================================
##                             (1) NC Search   (2) FL Search  
## -----------------------------------------------------------
## (Intercept)                      0.0862 **        0.0263 **
##                                 (0.0037)         (0.0005)  
## Female Officer                  -0.0256 **       -0.0038 **
##                                 (0.0020)         (0.0002)  
## Black Officer                   -0.0292 **       -0.0028 **
##                                 (0.0015)         (0.0001)  
## White Female                    -0.0086 **       -0.0026 **
##                                 (0.0019)         (0.0001)  
## Black Male                       0.0465 **        0.0066 **
##                                 (0.0016)         (0.0001)  
## Black Female                    -0.0204 **       -0.0015 **
##                                 (0.0017)         (0.0002)  
## Latino Male                                       0.0015 **
##                                                  (0.0001)  
## Latina Female                                    -0.0020 **
##                                                  (0.0002)  
## Investigatory Stop Purpose       0.0285 **        0.0055 **
##                                 (0.0012)         (0.0001)  
## -----------------------------------------------------------
## R^2                              0.0713           0.0092   
## Adj. R^2                         0.0711           0.0091   
## Num. obs.                   150547          2712478        
## ===========================================================
## ** p < 0.01; * p < 0.05
# Figure 2
fl.of.pred = predict(fl.search,
                     newdata = data.frame("of_gender"=c(0,1),"race_gender"=0,
                                            "subject_age"=35,"out_of_state"=0,
                                            "investigatory"=1,
                                          "officer_years_of_service"=6,
                                          "of_race"=0,"officer_age"=39,
                                          "hour_of_day"=15,
                                          "month"="05","year"=2013,
                                          "county_name"="Orange County"),
                     type="response",se.fit=T)
nc.of.pred = predict(nc.search,
                     newdata = data.frame("of_gender"=c(0,1),
                                          "race_gender"=0,
                                          "subject_age"=36,
                                          "investigatory"=1,
                                          "Officer_Years_of_Service"=10.25,
                                          "of_race"=0,"month"="01",
                                          "year"=2019,"CMPD_Division"="South Division"),
                     type="response",se.fit=T)



pred.df = data.frame("Department" = c("Charlotte Police Department",
                                      "Charlotte Police Department",
                                      "Florida Highway Patrol",
                                      "Florida Highway Patrol"),
                     "Gender" = c("Male","Female","Male","Female"),
                     "Predict" = c(nc.of.pred$fit,
                                   fl.of.pred$fit),
                     "Lower"=c(nc.of.pred$fit-1.96*nc.of.pred$se.fit,
                               fl.of.pred$fit-1.96*fl.of.pred$se.fit),
                     "Upper"=c(nc.of.pred$fit+1.96*nc.of.pred$se.fit,
                               fl.of.pred$fit+1.96*fl.of.pred$se.fit))

png("Figures/Fig2_PredProb.png",
    900,514)
ggplot(data = pred.df, aes(x=Gender,y=Predict)) + 
  geom_point(size=4) +  
  geom_errorbar(aes(ymin = Lower, ymax = Upper),
                width=.2,size = 0.75,                   
                position=position_dodge(.9)) + 
  ylab("Expected Probbility of a Search") +
  xlab("Officer Sex") +
  theme_bw(base_size=15) +facet_wrap(~Department) 
dev.off()
## quartz_off_screen 
##                 2
pred.df$Predict[1]/pred.df$Predict[2]
## [1] 2.245964
pred.df$Predict[3]/pred.df$Predict[4]
## [1] 2.720538
# Table 3
tab3 = data.frame("Officer Gender"=c("Male","Female"),
                  "Searches"=table(fl$of_gender[!is.na(fl$search_occur)],
                                   fl$search_occur[!is.na(fl$search_occur)])[,2],
                  "Contraband"=table(fl$of_gender[!is.na(fl$search_occur)],
                                     fl$contra[!is.na(fl$search_occur)])[,2],
                  "Contraband Hit Rate"=table(fl$of_gender[!is.na(fl$search_occur)],
                                              fl$contra[!is.na(fl$search_occur)])[,2]/
                    table(fl$of_gender[!is.na(fl$search_occur)],
                          fl$search_occur[!is.na(fl$search_occur)])[,2],
                  "Difference"=c((table(fl$of_gender[!is.na(fl$search_occur)],
                                        fl$contra[!is.na(fl$search_occur)])[,2]/
                                    table(fl$of_gender[!is.na(fl$search_occur)],
                                          fl$search_occur[!is.na(fl$search_occur)])[,2])[1]-
                                   (table(fl$of_gender[!is.na(fl$search_occur)],
                                          fl$contra[!is.na(fl$search_occur)])[,2]/
                                      table(fl$of_gender[!is.na(fl$search_occur)],
                                            fl$search_occur[!is.na(fl$search_occur)])[,2])[2],NA))
tab3
##   Officer.Gender Searches Contraband Contraband.Hit.Rate Difference
## 0           Male    16422       4911           0.2990501 -0.1163911
## 1         Female      272        113           0.4154412         NA
prop.test(table(fl$of_gender[fl$search_occur==1],
                fl$contra[fl$search_occur==1]))
## 
##  2-sample test for equality of proportions with continuity correction
## 
## data:  table(fl$of_gender[fl$search_occur == 1], fl$contra[fl$search_occur == 1])
## X-squared = 16.681, df = 1, p-value = 4.423e-05
## alternative hypothesis: two.sided
## 95 percent confidence interval:
##  0.05554105 0.17724120
## sample estimates:
##    prop 1    prop 2 
## 0.7009499 0.5845588
# Table 4
load("Data/FlContra_OLS.RData")
load("Data/FlSearchRate_OLS.RData")
load("Data/FlStopRate_OLS.RData")
screenreg(list(fl.contra,contra.search.rate.reg,contra.stop.rate.reg),
          stars=c(0.01,0.05),
          custom.coef.map = list("(Intercept)"="(Intercept)",
                                 "factor(of_gender)1"="Female Officer",
                                 "factor(of_race)1"="Black Officer",
                                 "factor(race_gender)1"="White Female",
                                 "factor(race_gender)2"="Black Male",
                                 "factor(race_gender)3"="Black Female",
                                 "factor(race_gender)4"="Latino Male",
                                 "factor(race_gender)5"="Latina Female",
                                 "investigatory" = "Investigatory Stop Purpose"),
          custom.model.names = c("(1) Contra|Search",
                                 "(2) Hit Rate, per 10 Searches",
                                 "(3) Hit Rate, per 100 Stops"),
          digits=4)
## 
## =========================================================================================================
##                             (1) Contra|Search  (2) Hit Rate, per 10 Searches  (3) Hit Rate, per 100 Stops
## ---------------------------------------------------------------------------------------------------------
## (Intercept)                     0.1118 **         0.3006                           0.1380 **             
##                                (0.0421)          (0.2148)                         (0.0176)               
## Female Officer                  0.1026 **         1.1223 **                       -0.0771 **             
##                                (0.0294)          (0.2760)                         (0.0117)               
## Black Officer                   0.0578 **         0.7640 **                       -0.0976 **             
##                                (0.0199)          (0.2030)                         (0.0096)               
## White Female                   -0.0025            0.0512                          -0.0557 **             
##                                (0.0144)          (0.1467)                         (0.0096)               
## Black Male                     -0.0531 **        -0.4505 **                        0.0975 **             
##                                (0.0097)          (0.1058)                         (0.0104)               
## Black Female                   -0.0594 **        -0.4565 **                       -0.0519 **             
##                                (0.0172)          (0.1728)                         (0.0117)               
## Latino Male                    -0.0909 **        -0.8755 **                       -0.0021                
##                                (0.0115)          (0.1195)                         (0.0107)               
## Latina Female                  -0.0027            0.0346                          -0.0669 **             
##                                (0.0267)          (0.2586)                         (0.0128)               
## Investigatory Stop Purpose      0.3394 **         3.4794 **                        0.2534 **             
##                                (0.0112)          (0.1102)                         (0.0066)               
## ---------------------------------------------------------------------------------------------------------
## R^2                             0.1346            0.1311                           0.0036                
## Adj. R^2                        0.1265            0.1285                           0.0036                
## Num. obs.                   12782              9677                           747784                     
## =========================================================================================================
## ** p < 0.01; * p < 0.05
###
### 3. Appendix A: Full Regression Results
###

screenreg(list(nc.search,fl.search,
               fl.contra,contra.search.rate.reg,contra.stop.rate.reg),
          stars=c(0.01,0.05),
          custom.coef.map = list("(Intercept)"="(Intercept)",
                                 "factor(of_gender)1"="Female Officer",
                                 "factor(of_race)1"="Black Officer",
                                 "officer_age"="Officer Age",
                                 "factor(of_age)2"="Officer Age: 30-64",
                                 "factor(of_age)3"="Officer Age: 65+",
                                 "officer_years_of_service"="Officer Years of Service",
                                 "Officer_Years_of_Service"="Officer Years of Service",
                                 "factor(of_exper)1"="Experienced Officer",
                                 "factor(race_gender)1"="White Female",
                                 "factor(race_gender)2"="Black Male",
                                 "factor(race_gender)3"="Black Female",
                                 "factor(race_gender)4"="Latino Male",
                                 "factor(race_gender)5"="Latina Female",
                                 "subject_age"="Driver Age",
                                 "factor(driver_age)2"="Driver Age: 30-64",
                                 "factor(driver_age)3"="Driver Age: 65+",
                                 "investigatory" = "Investigatory Stop Purpose",
                                 "out_of_state"="Out of State"),
          custom.model.names = c("(1)","(2)",
                                 "(3)","(4)","(5)"),
          digits=3)
## 
## ===================================================================================================
##                             (1)            (2)             (3)           (4)          (5)          
## ---------------------------------------------------------------------------------------------------
## (Intercept)                      0.086 **        0.026 **      0.112 **     0.301          0.138 **
##                                 (0.004)         (0.001)       (0.042)      (0.215)        (0.018)  
## Female Officer                  -0.026 **       -0.004 **      0.103 **     1.122 **      -0.077 **
##                                 (0.002)         (0.000)       (0.029)      (0.276)        (0.012)  
## Black Officer                   -0.029 **       -0.003 **      0.058 **     0.764 **      -0.098 **
##                                 (0.001)         (0.000)       (0.020)      (0.203)        (0.010)  
## Officer Age                                     -0.000 **     -0.004 **                            
##                                                 (0.000)       (0.001)                              
## Officer Age: 30-64                                                         -0.375 **      -0.044 **
##                                                                            (0.096)        (0.008)  
## Officer Age: 65+                                                           -0.829         -0.262   
##                                                                            (4.048)        (0.183)  
## Officer Years of Service        -0.002 **        0.000 **     -0.000                               
##                                 (0.000)         (0.000)       (0.001)                              
## Experienced Officer                                                        -0.026          0.053 **
##                                                                            (0.086)        (0.007)  
## White Female                    -0.009 **       -0.003 **     -0.003        0.051         -0.056 **
##                                 (0.002)         (0.000)       (0.014)      (0.147)        (0.010)  
## Black Male                       0.046 **        0.007 **     -0.053 **    -0.451 **       0.098 **
##                                 (0.002)         (0.000)       (0.010)      (0.106)        (0.010)  
## Black Female                    -0.020 **       -0.001 **     -0.059 **    -0.456 **      -0.052 **
##                                 (0.002)         (0.000)       (0.017)      (0.173)        (0.012)  
## Latino Male                                      0.001 **     -0.091 **    -0.876 **      -0.002   
##                                                 (0.000)       (0.011)      (0.120)        (0.011)  
## Latina Female                                   -0.002 **     -0.003        0.035         -0.067 **
##                                                 (0.000)       (0.027)      (0.259)        (0.013)  
## Driver Age                      -0.001 **       -0.000 **     -0.003 **                            
##                                 (0.000)         (0.000)       (0.000)                              
## Driver Age: 30-64                                                          -0.485 **      -0.123 **
##                                                                            (0.085)        (0.007)  
## Driver Age: 65+                                                            -1.113 *       -0.187 **
##                                                                            (0.446)        (0.012)  
## Investigatory Stop Purpose       0.028 **        0.006 **      0.339 **     3.479 **       0.253 **
##                                 (0.001)         (0.000)       (0.011)      (0.110)        (0.007)  
## Out of State                                     0.001 **     -0.053 **    -0.667 **       0.037 **
##                                                 (0.000)       (0.011)      (0.110)        (0.008)  
## ---------------------------------------------------------------------------------------------------
## R^2                              0.071           0.009         0.135        0.131          0.004   
## Adj. R^2                         0.071           0.009         0.127        0.128          0.004   
## Num. obs.                   150547         2712478         12782         9677         747784       
## ===================================================================================================
## ** p < 0.01; * p < 0.05
###
### 4. Appendix B: Alternative Test of Differences in Search and Contraband Hit Rates
###

# Florida
fl$stop = 1
fl$of_exper = ifelse(fl$officer_years_of_service>=
                       mean(fl$officer_years_of_service,na.rm=T),1,0)
fl$of_age = ifelse(fl$officer_age<30,1,
                   ifelse(fl$officer_age>64,3,2))
fl$driver_age = ifelse(fl$subject_age<30,1,
                       ifelse(fl$subject_age>64,3,2))
fl$hour_of_day=as.numeric(fl$hour_of_day)
fl$tod = ifelse(fl$hour_of_day<3,1,
                ifelse(fl$hour_of_day<6,2,
                       ifelse(fl$hour_of_day<9,3,
                              ifelse(fl$hour_of_day<12,4,
                                     ifelse(fl$hour_of_day<15,5,
                                            ifelse(fl$hour_of_day<18,6,
                                                   ifelse(fl$hour_of_day<21,7,8)))))))

fl.ag = aggregate(fl[!is.na(fl$search_occur),c("stop","search_occur","contra")], 
                  by = list(fl$tod[!is.na(fl$search_occur)],
                            fl$officer_race[!is.na(fl$search_occur)],
                            fl$officer_sex[!is.na(fl$search_occur)],
                            fl$of_exper[!is.na(fl$search_occur)],
                            fl$race_gender[!is.na(fl$search_occur)],
                            fl$driver_age[!is.na(fl$search_occur)],
                            fl$out_of_state[!is.na(fl$search_occur)],
                            fl$investigatory[!is.na(fl$search_occur)]),
                  sum,na.rm=T)
colnames(fl.ag) = c("tod",
                    "of_race","of_sex","of_exper","driver_rg",
                    "driver_age","out_of_state","invest",
                    "stop","search","contraband")
fl.ag.female = fl.ag[fl.ag$of_sex=="female",]
colnames(fl.ag.female)[c(3,9:11)] = c("female","stop.f",
                                       "search.f","contra.f")
fl.ag.male = fl.ag[fl.ag$of_sex=="male",]
colnames(fl.ag.male)[c(3,9:11)] = c("male","stop.m",
                                     "search.m","contra.m")

fl.matches = merge(fl.ag.female,fl.ag.male)
min.stops = 9
table(fl.matches$stop.f>min.stops&
        fl.matches$stop.m>min.stops)
## 
## FALSE  TRUE 
##  1461  1784
min.searches = 0
table(fl.matches$search.f>min.searches&
        fl.matches$search.m>min.searches)
## 
## FALSE  TRUE 
##  3084   161
table(fl.matches$search.f>min.searches&
        fl.matches$search.m>min.searches&
        fl.matches$stop.f>min.stops&
        fl.matches$stop.m>min.stops)
## 
## FALSE  TRUE 
##  3084   161
# North Carolina
nc$stop = 1
nc$search = ifelse(nc$Was_a_Search_Conducted=="Yes",1,0)
nc$driver_age = ifelse(nc$Driver_Age<30,1,
                       ifelse(nc$Driver_Age>65,3,2))
nc$of_exper = ifelse(nc$Officer_Years_of_Service>=mean(nc$Officer_Years_of_Service),
                     1,0)
nc.ag = aggregate(nc[,c("search","stop")], 
                  by = list(nc$CMPD_Division,
                            nc$Officer_Gender,nc$Officer_Race,
                            nc$of_exper,
                            nc$race_gender,nc$driver_age,
                            nc$investigatory,
                            nc$year),
                  sum)
nc.ag.female = nc.ag[nc.ag$Group.2=="Female",]
colnames(nc.ag.female) = c("division","female","race","of_exper",
                           "driver.rg","driver_age","investigatory",
                           "year",
                           "searches.f","stops.f")
nc.ag.male = nc.ag[nc.ag$Group.2=="Male",]
colnames(nc.ag.male) = c("division","male","race","of_exper",
                         "driver.rg","driver_age","investigatory",
                         "year",
                         "searches.m","stops.m")


# Searches
fl.matches$sr.f = fl.matches$search.f/fl.matches$stop.f
fl.matches$sr.m = fl.matches$search.m/fl.matches$stop.m
fl.matches$cr.f = fl.matches$contra.f/fl.matches$search.f
fl.matches$cr.m = fl.matches$contra.m/fl.matches$search.m
t.test(fl.matches$sr.f[fl.matches$stop.f>min.stops&
                         fl.matches$stop.m>min.stops],
       fl.matches$sr.m[fl.matches$stop.f>min.stops&
                         fl.matches$stop.m>min.stops],
       paired = T)
## 
##  Paired t-test
## 
## data:  fl.matches$sr.f[fl.matches$stop.f > min.stops & fl.matches$stop.m > min.stops] and fl.matches$sr.m[fl.matches$stop.f > min.stops & fl.matches$stop.m > min.stops]
## t = -13.359, df = 1783, p-value < 2.2e-16
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.003700686 -0.002753143
## sample estimates:
## mean of the differences 
##            -0.003226915
length(fl.matches$sr.f[fl.matches$stop.f>min.stops&
                         fl.matches$stop.m>min.stops])
## [1] 1784
mean(fl.matches$sr.f[fl.matches$stop.f>min.stops&
                       fl.matches$stop.m>min.stops])
## [1] 0.001355022
mean(fl.matches$sr.m[fl.matches$stop.f>min.stops&
                       fl.matches$stop.m>min.stops])
## [1] 0.004581936
nc.matches = merge(nc.ag.female,nc.ag.male)
min.stops = 9
nc.matches$sr.f = nc.matches$searches.f/nc.matches$stops.f
nc.matches$sr.m = nc.matches$searches.m/nc.matches$stops.m
t.test(nc.matches$sr.f[nc.matches$stops.f>min.stops&
                         nc.matches$stops.m>min.stops],
       nc.matches$sr.m[nc.matches$stops.f>min.stops&
                         nc.matches$stops.m>min.stops],
       paired = T)
## 
##  Paired t-test
## 
## data:  nc.matches$sr.f[nc.matches$stops.f > min.stops & nc.matches$stops.m > min.stops] and nc.matches$sr.m[nc.matches$stops.f > min.stops & nc.matches$stops.m > min.stops]
## t = -4.0127, df = 352, p-value = 7.335e-05
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.024123468 -0.008254384
## sample estimates:
## mean of the differences 
##             -0.01618893
length(nc.matches$sr.f[nc.matches$stops.f>min.stops&
                         nc.matches$stops.m>min.stops])
## [1] 353
mean(nc.matches$sr.f[nc.matches$stops.f>min.stops&
                       nc.matches$stops.m>min.stops])
## [1] 0.05538775
mean(nc.matches$sr.m[nc.matches$stops.f>min.stops&
                       nc.matches$stops.m>min.stops],)
## [1] 0.07157667
# Contraband
t.test(fl.matches$cr.f[fl.matches$search.f>min.searches&
                         fl.matches$search.m>min.searches&
                         fl.matches$stop.f>min.stops&
                         fl.matches$stop.m>min.stops],
       fl.matches$cr.m[fl.matches$search.f>min.searches&
                         fl.matches$search.m>min.searches&
                         fl.matches$stop.f>min.stops&
                         fl.matches$stop.m>min.stops],
       paired = T)
## 
##  Paired t-test
## 
## data:  fl.matches$cr.f[fl.matches$search.f > min.searches & fl.matches$search.m > min.searches & fl.matches$stop.f > min.stops & fl.matches$stop.m > min.stops] and fl.matches$cr.m[fl.matches$search.f > min.searches & fl.matches$search.m > min.searches & fl.matches$stop.f > min.stops & fl.matches$stop.m > min.stops]
## t = 2.6679, df = 160, p-value = 0.008419
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  0.02401357 0.16088431
## sample estimates:
## mean of the differences 
##              0.09244894
length(fl.matches$cr.f[fl.matches$search.f>min.searches&
                         fl.matches$search.m>min.searches&
                         fl.matches$stop.f>min.stops&
                         fl.matches$stop.m>min.stops])
## [1] 161
mean(fl.matches$cr.f[fl.matches$search.f>min.searches&
                       fl.matches$search.m>min.searches&
                       fl.matches$stop.f>min.stops&
                       fl.matches$stop.m>min.stops])
## [1] 0.4090506
mean(fl.matches$cr.m[fl.matches$search.f>min.searches&
                       fl.matches$search.m>min.searches&
                       fl.matches$stop.f>min.stops&
                       fl.matches$stop.m>min.stops])
## [1] 0.3166016
###
### 5. Appendix C: Logistic Regrssion Models
###

rm(list = ls())

load("Data/FlContra_Logit.RData")
load("Data/FLSearch_Logit.RData")
load("Data/NCSearch_Logit.RData")

texreg(list(nc.search,fl.search,fl.contra),
          stars=c(0.01,0.05),
          custom.coef.map = list("(Intercept)"="(Intercept)",
                                 "factor(of_gender)1"="Female Officer",
                                 "factor(of_race)1"="Black Officer",
                                 "factor(of_race)2"="Latinx Officer",
                                 "factor(of_race)3"="Asain/Pacific Islander Officer",
                                 "factor(of_race)4"="Other Race Officer",
                                 "officer_age"="Officer Age",
                                 "officer_years_of_service"="Officer Years of Service",
                                 "Officer_Years_of_Service"="Officer Years of Service",
                                 "factor(race_gender)1"="White Female",
                                 "factor(race_gender)2"="Black Male",
                                 "factor(race_gender)3"="Black Female",
                                 "factor(race_gender)4"="Latino Male",
                                 "factor(race_gender)5"="Latina Female",
                                 "subject_age"="Driver Age",
                                 "investigatory" = "Investigatory Stop Purpose",
                                 "out_of_state"="Out of State"),
          custom.model.names = c("(1) NC Search",
                                 "(2) FL Search",
                                 "(3) FL Contra|Search"),
          digits=4)
## 
## \begin{table}
## \begin{center}
## \begin{tabular}{l c c c}
## \hline
##  & (1) NC Search & (2) FL Search & (3) FL Contra|Search \\
## \hline
## (Intercept)                    & $-1.9244^{**}$ & $-2.8175^{**}$ & $-17.9811$     \\
##                                & $(0.0906)$     & $(0.0900)$     & $(148.7052)$   \\
## Female Officer                 & $-0.4702^{**}$ & $-1.4253^{**}$ & $0.4986^{**}$  \\
##                                & $(0.0477)$     & $(0.0674)$     & $(0.1547)$     \\
## Black Officer                  & $-0.7213^{**}$ & $-1.0929^{**}$ & $0.2932^{**}$  \\
##                                & $(0.0387)$     & $(0.0441)$     & $(0.1060)$     \\
## Latinx Officer                 &                & $-0.3512^{**}$ & $-0.1044$      \\
##                                &                & $(0.0363)$     & $(0.0924)$     \\
## Asain/Pacific Islander Officer &                & $-1.0206^{**}$ & $0.7392$       \\
##                                &                & $(0.2019)$     & $(0.5612)$     \\
## Other Race Officer             &                & $-0.8249^{**}$ & $0.8317^{*}$   \\
##                                &                & $(0.1632)$     & $(0.3917)$     \\
## Officer Age                    &                & $-0.0221^{**}$ & $-0.0202^{**}$ \\
##                                &                & $(0.0012)$     & $(0.0036)$     \\
## Officer Years of Service       & $-0.0770^{**}$ & $0.0129^{**}$  & $-0.0002$      \\
##                                & $(0.0023)$     & $(0.0017)$     & $(0.0045)$     \\
## White Female                   & $-0.6166^{**}$ & $-0.8276^{**}$ & $-0.0151$      \\
##                                & $(0.0751)$     & $(0.0337)$     & $(0.0782)$     \\
## Black Male                     & $0.8877^{**}$  & $0.8883^{**}$  & $-0.2900^{**}$ \\
##                                & $(0.0436)$     & $(0.0228)$     & $(0.0534)$     \\
## Black Female                   & $-0.4638^{**}$ & $-0.2870^{**}$ & $-0.3230^{**}$ \\
##                                & $(0.0518)$     & $(0.0404)$     & $(0.0960)$     \\
## Latino Male                    &                & $0.3641^{**}$  & $-0.5462^{**}$ \\
##                                &                & $(0.0276)$     & $(0.0663)$     \\
## Latina Female                  &                & $-0.7432^{**}$ & $0.0039$       \\
##                                &                & $(0.0624)$     & $(0.1465)$     \\
## Driver Age                     & $-0.0422^{**}$ & $-0.0450^{**}$ & $-0.0161^{**}$ \\
##                                & $(0.0012)$     & $(0.0008)$     & $(0.0022)$     \\
## Investigatory Stop Purpose     & $0.6995^{**}$  & $1.5916^{**}$  & $17.9495$      \\
##                                & $(0.0298)$     & $(0.0262)$     & $(148.7051)$   \\
## Out of State                   &                & $0.3653^{**}$  & $-0.3378^{**}$ \\
##                                &                & $(0.0269)$     & $(0.0667)$     \\
## \hline
## AIC                            & $49914.2052$   & $137958.1571$  & $13507.4833$   \\
## BIC                            & $50261.4763$   & $139508.5753$  & $14402.1785$   \\
## Log Likelihood                 & $-24922.1026$  & $-68858.0786$  & $-6633.7416$   \\
## Deviance                       & $49844.2052$   & $137716.1571$  & $13267.4833$   \\
## Num. obs.                      & $150547$       & $2712478$      & $12782$        \\
## \hline
## \multicolumn{4}{l}{\scriptsize{$^{**}p<0.01$; $^{*}p<0.05$}}
## \end{tabular}
## \caption{Statistical models}
## \label{table:coefficients}
## \end{center}
## \end{table}
###
### 6. Appendix C: Fixed Effects 
###

rm(list = ls())

load("Data/FLSearch_OLS_FE.RData")
load("Data/FlContra_OLS_FE.RData")
load("Data/FlSearchRate_OLS_FE.RData")
load("Data/FlStopRate_OLS_FE.RData")

texreg(list(fl.search,
               fl.contra,
               contra.search.rate.reg,
               contra.stop.rate.reg),
          stars=c(0.01,0.05),
          custom.coef.map = list("(Intercept)"="(Intercept)",
                                 "factor(of_gender)1"="Female Officer",
                                 "factor(of_race)1"="Black Officer",
                                 "officer_age"="Officer Age",
                                 "factor(of_age)2"="Officer Age: 30-64",
                                 "factor(of_age)3"="Officer Age: 65+",
                                 "officer_years_of_service"="Officer Years of Service",
                                 "Officer_Years_of_Service"="Officer Years of Service",
                                 "factor(of_exper)1"="Experienced Officer",
                                 "factor(race_gender)1"="White Female",
                                 "factor(race_gender)2"="Black Male",
                                 "factor(race_gender)3"="Black Female",
                                 "factor(race_gender)4"="Latino Male",
                                 "factor(race_gender)5"="Latina Female",
                                 "subject_age"="Driver Age",
                                 "factor(driver_age)2"="Driver Age: 30-64",
                                 "factor(driver_age)3"="Driver Age: 65+",
                                 "investigatory" = "Investigatory Stop Purpose",
                                 "out_of_state"="Out of State"),
          custom.model.names = c("(1) Search",
                                 "(2) Contra|Search",
                                 "(3) Hit Rate, per 10 Searches",
                                 "(4) Hit Rate, per 100 Stops"),
          digits=4)
## 
## \begin{table}
## \begin{center}
## \begin{tabular}{l c c c c}
## \hline
##  & (1) Search & (2) Contra|Search & (3) Hit Rate, per 10 Searches & (4) Hit Rate, per 100 Stops \\
## \hline
## (Intercept)                        & $0.0142^{**}$   & $0.1363^{*}$   & $0.2596$       & $0.0707^{**}$   \\
##                                    & $(0.0017)$      & $(0.0567)$     & $(0.2384)$     & $(0.0232)$      \\
## Female Officer                     & $-0.0026^{*}$   & $0.0916^{*}$   & $0.9424^{*}$   & $-0.0531$       \\
##                                    & $(0.0013)$      & $(0.0376)$     & $(0.3793)$     & $(0.0334)$      \\
## Black Officer                      & $-0.0035^{**}$  & $0.0541$       & $0.3139$       & $-0.0894^{**}$  \\
##                                    & $(0.0012)$      & $(0.0399)$     & $(0.4081)$     & $(0.0306)$      \\
## Officer Age                        & $-0.0001^{**}$  & $-0.0048^{**}$ &                &                 \\
##                                    & $(0.0000)$      & $(0.0012)$     &                &                 \\
## Officer Age: 30-64                 &                 &                & $-0.4058^{**}$ & $-0.0231$       \\
##                                    &                 &                & $(0.1474)$     & $(0.0160)$      \\
## Officer Age: 65+                   &                 &                & $-0.5371$      & $-0.1241$       \\
##                                    &                 &                & $(4.0924)$     & $(0.2141)$      \\
## Officer Years of Service           & $0.0002^{**}$   & $0.0024$       &                &                 \\
##                                    & $(0.0000)$      & $(0.0016)$     &                &                 \\
## Experienced Officer                &                 &                & $0.3207^{*}$   & $0.0692^{**}$   \\
##                                    &                 &                & $(0.1614)$     & $(0.0151)$      \\
## White Female                       & $-0.0022^{**}$  & $-0.0037$      & $0.0647$       & $-0.0545^{**}$  \\
##                                    & $(0.0001)$      & $(0.0142)$     & $(0.1418)$     & $(0.0096)$      \\
## Black Male                         & $0.0051^{**}$   & $-0.0535^{**}$ & $-0.5417^{**}$ & $0.0851^{**}$   \\
##                                    & $(0.0001)$      & $(0.0097)$     & $(0.1042)$     & $(0.0104)$      \\
## Black Female                       & $-0.0019^{**}$  & $-0.0609^{**}$ & $-0.4922^{**}$ & $-0.0630^{**}$  \\
##                                    & $(0.0002)$      & $(0.0170)$     & $(0.1682)$     & $(0.0116)$      \\
## Latino Male                        & $0.0013^{**}$   & $-0.0909^{**}$ & $-0.8668^{**}$ & $-0.0088$       \\
##                                    & $(0.0001)$      & $(0.0114)$     & $(0.1177)$     & $(0.0107)$      \\
## Latina Female                      & $-0.0019^{**}$  & $-0.0114$      & $-0.1267$      & $-0.0675^{**}$  \\
##                                    & $(0.0002)$      & $(0.0264)$     & $(0.2512)$     & $(0.0128)$      \\
## Driver Age                         & $-0.0001^{**}$  & $-0.0023^{**}$ &                &                 \\
##                                    & $(0.0000)$      & $(0.0004)$     &                &                 \\
## Driver Age: 30-64                  &                 &                & $-0.3525^{**}$ & $-0.1190^{**}$  \\
##                                    &                 &                & $(0.0829)$     & $(0.0069)$      \\
## Driver Age: 65+                    &                 &                & $-0.8633^{*}$  & $-0.1688^{**}$  \\
##                                    &                 &                & $(0.4308)$     & $(0.0117)$      \\
## Investigatory Stop Purpose         & $0.0041^{**}$   & $0.3340^{**}$  & $3.3725^{**}$  & $0.2428^{**}$   \\
##                                    & $(0.0001)$      & $(0.0112)$     & $(0.1081)$     & $(0.0067)$      \\
## Out of State                       & $0.0018^{**}$   & $-0.0544^{**}$ & $-0.5205^{**}$ & $0.0317^{**}$   \\
##                                    & $(0.0001)$      & $(0.0112)$     & $(0.1093)$     & $(0.0083)$      \\
## \hline
## AIC                                & $-6993843.0503$ & $15022.3545$   & $54081.7043$   & $3674955.2660$  \\
## BIC                                & $-6992267.0054$ & $15931.9613$   & $54311.3845$   & $3675324.0618$  \\
## Log Likelihood                     & $3497044.5251$  & $-7389.1773$   & $-27008.8521$  & $-1837445.6330$ \\
## Num. obs.                          & $2712478$       & $12782$        & $9677$         & $747784$        \\
## Num. groups: officer\_id\_hash     & $1419$          & $599$          & $$             & $$              \\
## Var: officer\_id\_hash (Intercept) & $0.0002$        & $0.0150$       & $$             & $$              \\
## Var: Residual                      & $0.0044$        & $0.1744$       & $14.8268$      & $7.9441$        \\
## Num. groups: officer\_id           & $$              & $$             & $602$          & $1424$          \\
## Var: officer\_id (Intercept)       & $$              & $$             & $2.1381$       & $0.1270$        \\
## \hline
## \multicolumn{5}{l}{\scriptsize{$^{**}p<0.01$; $^{*}p<0.05$}}
## \end{tabular}
## \caption{Statistical models}
## \label{table:coefficients}
## \end{center}
## \end{table}
###
### 7. Appendix D: Interaction Models
###

rm(list = ls())

# Table 1. Officer Experience
load("Data/FLSearch_Exper_OLS.RData")
load("Data/NCSearch_Exper_OLS.RData")
load("Data/FlContra_Exper_OLS.RData")
load("Data/FlSearchRate_Exper_OLS.RData")
load("Data/FlStopRate_Exper_OLS.RData")

texreg(list(nc.search.exper,fl.search.exper,fl.contra.exper,
            contra.search.rate.exper,contra.stop.rate.exper),
       stars=c(0.05,0.01),
       custom.coef.map = list("factor(of_gender)1"="Female Officer",
                              "officer_years_of_service"="Officer Years of Service",
                              "Officer_Years_of_Service"="Officer Years of Service",
                              "factor(of_exper)1"="Experienced Officer",
                              "factor(of_gender)1:officer_years_of_service"="Female Officer * Exper.",
                              "factor(of_gender)1:Officer_Years_of_Service"="Female Officer * Exper.",
                              "factor(of_gender)1:factor(of_exper)1"="Female Officer * Exper."),
       digits = 3)
## 
## \begin{table}
## \begin{center}
## \begin{tabular}{l c c c c c}
## \hline
##  & Model 1 & Model 2 & Model 3 & Model 4 & Model 5 \\
## \hline
## Female Officer           & $-0.025^{**}$ & $-0.004^{**}$ & $0.112^{**}$ & $0.971^{**}$ & $-0.059^{**}$ \\
##                          & $(0.003)$     & $(0.000)$     & $(0.040)$    & $(0.364)$    & $(0.015)$     \\
## Officer Years of Service & $-0.002^{**}$ & $0.000^{**}$  & $-0.000$     &              &               \\
##                          & $(0.000)$     & $(0.000)$     & $(0.001)$    &              &               \\
## Experienced Officer      &               &               &              & $-0.043$     & $0.056^{**}$  \\
##                          &               &               &              & $(0.087)$    & $(0.008)$     \\
## Female Officer * Exper.  & $-0.000$      & $-0.000$      & $-0.002$     & $0.443$      & $-0.047^{*}$  \\
##                          & $(0.000)$     & $(0.000)$     & $(0.005)$    & $(0.558)$    & $(0.024)$     \\
## \hline
## R$^2$                    & $0.071$       & $0.009$       & $0.135$      & $0.129$      & $0.003$       \\
## Adj. R$^2$               & $0.071$       & $0.009$       & $0.126$      & $0.127$      & $0.003$       \\
## Num. obs.                & $150547$      & $2712478$     & $12782$      & $9677$       & $747784$      \\
## \hline
## \multicolumn{6}{l}{\scriptsize{$^{**}p<0.01$; $^{*}p<0.05$}}
## \end{tabular}
## \caption{Statistical models}
## \label{table:coefficients}
## \end{center}
## \end{table}
# Table 2. Prop Female
load("Data/FLSearch_Prop_OLS.RData")
load("Data/FlContra_Prop_OLS.RData")

texreg(list(fl.search.prop,fl.contra.prop),
       stars=c(0.05,0.01),
       custom.coef.map = list("factor(of_gender)1"="Female Officer",
                              "female.prop"="Female Proportion of Proximate Force",
                              "factor(of_gender)1:female.prop"="Female Officer * Female Prop."),
       digits = 3)
## 
## \begin{table}
## \begin{center}
## \begin{tabular}{l c c}
## \hline
##  & Model 1 & Model 2 \\
## \hline
## Female Officer                       & $-0.003^{**}$ & $0.434^{**}$  \\
##                                      & $(0.001)$     & $(0.105)$     \\
## Female Proportion of Proximate Force & $-0.004$      & $-0.269$      \\
##                                      & $(0.002)$     & $(0.203)$     \\
## Female Officer * Female Prop.        & $-0.010$      & $-3.350^{**}$ \\
##                                      & $(0.006)$     & $(1.020)$     \\
## \hline
## R$^2$                                & $0.009$       & $0.136$       \\
## Adj. R$^2$                           & $0.009$       & $0.127$       \\
## Num. obs.                            & $2712478$     & $12782$       \\
## \hline
## \multicolumn{3}{l}{\scriptsize{$^{**}p<0.01$; $^{*}p<0.05$}}
## \end{tabular}
## \caption{Statistical models}
## \label{table:coefficients}
## \end{center}
## \end{table}
# Table 3. Stop Type
load("Data/FLSearch_StopType_OLS.RData")
load("Data/NCSearch_StopType_OLS.RData")
load("Data/FlContra_StopType_OLS.RData")
load("Data/FlSearchRate_StopType_OLS.RData")
load("Data/FlStopRate_StopType_OLS.RData")

texreg(list(nc.search.st,fl.search.st,fl.contra.st,
            contra.search.rate.st,contra.stop.rate.st),
       stars=c(0.05,0.01),
       custom.coef.map = list("(Intercept)"="(Intercept)",
                              "factor(of_gender)1"="Female Officer",
                              "factor(of_race)1"="Black Officer",
                              "officer_age"="Officer Age",
                              "factor(of_age)2"="Officer Age: 30-64",
                              "factor(of_age)3"="Officer Age: 65+",
                              "officer_years_of_service"="Officer Years of Service",
                              "Officer_Years_of_Service"="Officer Years of Service",
                              "factor(of_exper)1"="Experienced Officer",
                              "factor(race_gender)1"="White Female",
                              "factor(race_gender)2"="Black Male",
                              "factor(race_gender)3"="Black Female",
                              "factor(race_gender)4"="Latino Male",
                              "factor(race_gender)5"="Latina Female",
                              "subject_age"="Driver Age",
                              "factor(driver_age)2"="Driver Age: 30-64",
                              "factor(driver_age)3"="Driver Age: 65+",
                              "investigatory" = "Investigatory Stop Purpose",
                              "out_of_state"="Out of State"),
       digits = 3)
## 
## \begin{table}
## \begin{center}
## \begin{tabular}{l c c c c c}
## \hline
##  & Model 1 & Model 2 & Model 3 & Model 4 & Model 5 \\
## \hline
## (Intercept)              & $0.145^{**}$  & $0.045^{**}$  & $0.485^{**}$  & $3.754^{**}$  & $0.449^{**}$  \\
##                          & $(0.006)$     & $(0.001)$     & $(0.048)$     & $(0.170)$     & $(0.025)$     \\
## Female Officer           & $-0.032^{**}$ & $-0.006^{**}$ & $0.114^{**}$  & $1.322^{**}$  & $-0.147^{**}$ \\
##                          & $(0.003)$     & $(0.000)$     & $(0.034)$     & $(0.323)$     & $(0.022)$     \\
## Black Officer            & $-0.039^{**}$ & $-0.005^{**}$ & $0.065^{**}$  & $0.892^{**}$  & $-0.195^{**}$ \\
##                          & $(0.002)$     & $(0.000)$     & $(0.023)$     & $(0.242)$     & $(0.019)$     \\
## Officer Age              &               & $-0.000^{**}$ & $-0.004^{**}$ &               &               \\
##                          &               & $(0.000)$     & $(0.001)$     &               &               \\
## Officer Age: 30-64       &               &               &               & $-0.495^{**}$ & $-0.096^{**}$ \\
##                          &               &               &               & $(0.115)$     & $(0.016)$     \\
## Officer Age: 65+         &               &               &               &               & $-0.436$      \\
##                          &               &               &               &               & $(0.310)$     \\
## Officer Years of Service & $-0.003^{**}$ & $0.000^{**}$  & $-0.000$      &               &               \\
##                          & $(0.000)$     & $(0.000)$     & $(0.001)$     &               &               \\
## Experienced Officer      &               &               &               & $-0.037$      & $0.103^{**}$  \\
##                          &               &               &               & $(0.104)$     & $(0.014)$     \\
## White Female             & $-0.018^{**}$ & $-0.004^{**}$ & $-0.004$      & $0.068$       & $-0.115^{**}$ \\
##                          & $(0.004)$     & $(0.000)$     & $(0.017)$     & $(0.174)$     & $(0.019)$     \\
## Black Male               & $0.055^{**}$  & $0.010^{**}$  & $-0.061^{**}$ & $-0.558^{**}$ & $0.184^{**}$  \\
##                          & $(0.003)$     & $(0.000)$     & $(0.011)$     & $(0.127)$     & $(0.020)$     \\
## Black Female             & $-0.028^{**}$ & $-0.002^{**}$ & $-0.068^{**}$ & $-0.562^{**}$ & $-0.105^{**}$ \\
##                          & $(0.003)$     & $(0.000)$     & $(0.020)$     & $(0.208)$     & $(0.023)$     \\
## Latino Male              &               & $0.002^{**}$  & $-0.109^{**}$ & $-1.087^{**}$ & $-0.004$      \\
##                          &               & $(0.000)$     & $(0.013)$     & $(0.143)$     & $(0.021)$     \\
## Latina Female            &               & $-0.003^{**}$ & $0.005$       & $0.091$       & $-0.135^{**}$ \\
##                          &               & $(0.000)$     & $(0.032)$     & $(0.314)$     & $(0.025)$     \\
## Driver Age               & $-0.002^{**}$ & $-0.000^{**}$ & $-0.003^{**}$ &               &               \\
##                          & $(0.000)$     & $(0.000)$     & $(0.000)$     &               &               \\
## Driver Age: 30-64        &               &               &               & $-0.630^{**}$ & $-0.244^{**}$ \\
##                          &               &               &               & $(0.101)$     & $(0.014)$     \\
## Driver Age: 65+          &               &               &               & $-1.573^{**}$ & $-0.398^{**}$ \\
##                          &               &               &               & $(0.567)$     & $(0.023)$     \\
## Out of State             &               & $0.003^{**}$  & $-0.065^{**}$ & $-0.864^{**}$ & $0.066^{**}$  \\
##                          &               & $(0.000)$     & $(0.013)$     & $(0.133)$     & $(0.016)$     \\
## \hline
## R$^2$                    & $0.071$       & $0.012$       & $0.084$       & $0.047$       & $0.003$       \\
## Adj. R$^2$               & $0.070$       & $0.012$       & $0.074$       & $0.045$       & $0.003$       \\
## Num. obs.                & $79523$       & $1474530$     & $11041$       & $8045$        & $382456$      \\
## \hline
## \multicolumn{6}{l}{\scriptsize{$^{**}p<0.01$; $^{*}p<0.05$}}
## \end{tabular}
## \caption{Statistical models}
## \label{table:coefficients}
## \end{center}
## \end{table}
# Table 4. Driver Characteristics
load("Data/FLInter_Search.RData")
load("Data/FLInter_Contra.RData")
load("Data/FLStopRate_Inter_OLS.RData")
load("Data/FLSearchRate_Inter_OLS.RData")
load("Data/NCInter_Search.RData")

texreg(list(nc.search.inter,fl.search.inter,fl.contra.inter,
            contra.search.rate.inter,contra.stop.rate.inter),
          stars=c(0.01,0.05),
          custom.coef.map = list("factor(of_gender)1"="Female Officer",
                                 "factor(subject_female)1"="Female Driver",
                                 "factor(of_race)1"="Black Officer",
                                 "factor(of_race)2"="Latinx Officer",
                                 "factor(subject_race2)1"="Black Driver",
                                 "factor(subject_race2)2"="Latinx Driver",
                                 "factor(of_gender)1:factor(subject_female)1"="Female Officer*Driver",
                                 "factor(of_race)1:factor(subject_race2)1"="Black Officer*Driver",
                                 "factor(of_race)2:factor(subject_race2)1"="Latinx Officer*Black Driver",
                                 "factor(of_race)1:factor(subject_race2)2"="Black Officer*Latinx Driver",
                                 "factor(of_race)2:factor(subject_race2)2"="Latinx Officer* Driver"),digits=3)
## 
## \begin{table}
## \begin{center}
## \begin{tabular}{l c c c c c}
## \hline
##  & Model 1 & Model 2 & Model 3 & Model 4 & Model 5 \\
## \hline
## Female Officer              & $-0.024^{**}$ & $-0.005^{**}$ & $0.111^{**}$  & $1.216^{**}$  & $-0.098^{**}$ \\
##                             & $(0.002)$     & $(0.000)$     & $(0.034)$     & $(0.315)$     & $(0.015)$     \\
## Female Driver               & $-0.046^{**}$ & $-0.004^{**}$ & $0.010$       & $0.956^{**}$  & $-0.071^{**}$ \\
##                             & $(0.001)$     & $(0.000)$     & $(0.010)$     & $(0.266)$     & $(0.014)$     \\
## Black Officer               & $-0.017^{**}$ & $-0.001^{**}$ & $0.020$       & $0.415$       & $-0.077^{**}$ \\
##                             & $(0.002)$     & $(0.000)$     & $(0.031)$     & $(0.330)$     & $(0.014)$     \\
## Latinx Officer              & $-0.020^{**}$ & $-0.000$      & $0.063^{*}$   & $1.338^{**}$  & $-0.032^{*}$  \\
##                             & $(0.005)$     & $(0.000)$     & $(0.026)$     & $(0.247)$     & $(0.015)$     \\
## Black Driver                & $0.027^{**}$  & $0.006^{**}$  & $-0.044^{**}$ & $-1.295^{**}$ & $0.035$       \\
##                             & $(0.001)$     & $(0.000)$     & $(0.009)$     & $(0.318)$     & $(0.019)$     \\
## Latinx Driver               & $-0.007^{**}$ & $0.002^{**}$  & $-0.075^{**}$ & $-0.800^{**}$ & $0.004$       \\
##                             & $(0.002)$     & $(0.000)$     & $(0.012)$     & $(0.129)$     & $(0.012)$     \\
## Female Officer*Driver       & $0.003$       & $0.003^{**}$  & $-0.042$      & $-0.315$      & $0.046$       \\
##                             & $(0.004)$     & $(0.000)$     & $(0.068)$     & $(0.641)$     & $(0.024)$     \\
## Black Officer*Driver        & $-0.018^{**}$ & $-0.005^{**}$ & $0.085^{*}$   & $0.790$       & $-0.056^{*}$  \\
##                             & $(0.003)$     & $(0.000)$     & $(0.043)$     & $(0.470)$     & $(0.023)$     \\
## Latinx Officer*Black Driver & $-0.001$      & $-0.003^{**}$ & $-0.167^{**}$ & $-1.922^{**}$ & $-0.113^{**}$ \\
##                             & $(0.006)$     & $(0.000)$     & $(0.033)$     & $(0.350)$     & $(0.025)$     \\
## Black Officer*Latinx Driver & $0.002$       & $-0.002^{**}$ & $0.018$       & $0.219$       & $-0.016$      \\
##                             & $(0.005)$     & $(0.000)$     & $(0.047)$     & $(0.513)$     & $(0.024)$     \\
## Latinx Officer* Driver      & $0.012$       & $-0.002^{**}$ & $-0.088^{**}$ & $-1.132^{**}$ & $-0.038$      \\
##                             & $(0.008)$     & $(0.000)$     & $(0.034)$     & $(0.348)$     & $(0.023)$     \\
## \hline
## R$^2$                       & $0.063$       & $0.009$       & $0.132$       & $0.132$       & $0.004$       \\
## Adj. R$^2$                  & $0.063$       & $0.009$       & $0.124$       & $0.130$       & $0.003$       \\
## Num. obs.                   & $176332$      & $2658706$     & $12718$       & $9677$        & $747784$      \\
## \hline
## \multicolumn{6}{l}{\scriptsize{$^{**}p<0.01$; $^{*}p<0.05$}}
## \end{tabular}
## \caption{Statistical models}
## \label{table:coefficients}
## \end{center}
## \end{table}
###
### 8. Appendix E: A Conservative Test with the Charlotte Police Department
###

load("Data/NorthCarolina.RData")

table(nc$year)
## 
##  2016  2017  2019  2020 
## 41113 46943 96498 33604
nc.search16 = lm(search~factor(race_gender)+subject_age+
                   investigatory+
                   factor(of_race)+
                   factor(of_gender)+Officer_Years_of_Service+
                   factor(month)+
                   factor(CMPD_Division),
                 data=nc,subset=nc$year==2016)
nc.search17 = lm(search~factor(race_gender)+subject_age+
                   investigatory+
                   factor(of_race)+
                   factor(of_gender)+Officer_Years_of_Service+
                   factor(month)+
                   factor(CMPD_Division),
                 data=nc,subset=nc$year==2017)
nc.search19 = lm(search~factor(race_gender)+subject_age+
                   investigatory+
                   factor(of_race)+
                   factor(of_gender)+Officer_Years_of_Service+
                   factor(month)+
                   factor(CMPD_Division),
                 data=nc,subset=nc$year==2019)
nc.search20 = lm(search~factor(race_gender)+subject_age+
                   investigatory+
                   factor(of_race)+
                   factor(of_gender)+Officer_Years_of_Service+
                   factor(month)+
                   factor(CMPD_Division),
                 data=nc,subset=nc$year==2020)
texreg(list(nc.search16,nc.search17,nc.search19,nc.search20),
       omit.coef = "Division*|month*",
       custom.coef.map = list("(Intercept)"="(Intercept)",
                              "factor(of_gender)1"="Female Officer",
                              "factor(of_race)1"="Black Officer",
                              "Officer_Years_of_Service"="Officer Years of Service",
                              "investigatory"="Investigatory Stop",
                              "factor(race_gender)1"="White Female",
                              "factor(race_gender)2"="Black Male",
                              "factor(race_gender)3"="Black Female",
                              "subject_age"="Driver Age"),
       stars=c(0.01,0.05))
## 
## \begin{table}
## \begin{center}
## \begin{tabular}{l c c c c}
## \hline
##  & Model 1 & Model 2 & Model 3 & Model 4 \\
## \hline
## (Intercept)              & $0.10^{**}$  & $0.09^{**}$  & $0.09^{**}$  & $0.10^{**}$  \\
##                          & $(0.01)$     & $(0.01)$     & $(0.01)$     & $(0.01)$     \\
## Female Officer           & $-0.03^{**}$ & $-0.03^{**}$ & $-0.02^{**}$ & $-0.02^{**}$ \\
##                          & $(0.00)$     & $(0.00)$     & $(0.00)$     & $(0.01)$     \\
## Black Officer            & $-0.03^{**}$ & $-0.03^{**}$ & $-0.03^{**}$ & $-0.04^{**}$ \\
##                          & $(0.00)$     & $(0.00)$     & $(0.00)$     & $(0.00)$     \\
## Officer Years of Service & $-0.00^{**}$ & $-0.00^{**}$ & $-0.00^{**}$ & $-0.00^{**}$ \\
##                          & $(0.00)$     & $(0.00)$     & $(0.00)$     & $(0.00)$     \\
## Investigatory Stop       & $0.02^{**}$  & $0.02^{**}$  & $0.03^{**}$  & $0.04^{**}$  \\
##                          & $(0.00)$     & $(0.00)$     & $(0.00)$     & $(0.00)$     \\
## White Female             & $-0.01^{**}$ & $-0.00$      & $-0.01^{**}$ & $-0.01$      \\
##                          & $(0.00)$     & $(0.00)$     & $(0.00)$     & $(0.01)$     \\
## Black Male               & $0.04^{**}$  & $0.05^{**}$  & $0.04^{**}$  & $0.04^{**}$  \\
##                          & $(0.00)$     & $(0.00)$     & $(0.00)$     & $(0.00)$     \\
## Black Female             & $-0.02^{**}$ & $-0.01^{**}$ & $-0.02^{**}$ & $-0.03^{**}$ \\
##                          & $(0.00)$     & $(0.00)$     & $(0.00)$     & $(0.01)$     \\
## Driver Age               & $-0.00^{**}$ & $-0.00^{**}$ & $-0.00^{**}$ & $-0.00^{**}$ \\
##                          & $(0.00)$     & $(0.00)$     & $(0.00)$     & $(0.00)$     \\
## \hline
## R$^2$                    & $0.07$       & $0.06$       & $0.08$       & $0.09$       \\
## Adj. R$^2$               & $0.07$       & $0.06$       & $0.08$       & $0.09$       \\
## Num. obs.                & $31275$      & $34701$      & $64501$      & $20070$      \\
## \hline
## \multicolumn{5}{l}{\scriptsize{$^{**}p<0.01$; $^{*}p<0.05$}}
## \end{tabular}
## \caption{Statistical models}
## \label{table:coefficients}
## \end{center}
## \end{table}