* * Kelsey Shoub * Oct. 23, 2017 * Chapter 9 * * Turning the more option off set more off * Opening the Log File log using "F:\TrafficStops\UpdatedBookChapters\Chapter9Cleaning\Chap9_25Oct2017.txt", t replace *********************************************** *********************************************** Part A *********************************************** * Loading in the data file (use the complete file) clear use "F:\TrafficStops\UpdatedBookChapters\NC_TrafficStops_2002-2016_Clean_5June2017.dta" * Setting the working directory cd F:\TrafficStops\UpdatedBookChapters\Chapter9Cleaning * * Table 1: Number of Drivers Receiving an Outcome Given Stop Type * sort race2 tab action investigation_stop, col by race2:tab action investigation_stop, col tab searchoccur investigation_stop,col by race2:tab searchoccur investigation_stop, col * * Table 3: * tab contraoccur investigation_stop, col by race2:tab contraoccur investigation_stop, col tab SearchType investigation_stop, col by race2:tab SearchType investigation_stop, col * * Regressions * rename Age age drop Top25 gen Top25 = 1 if agencydescription == "NC State Highway Patrol" replace Top25 = 2 if agencydescription == "Charlotte-Mecklenburg Police Department" replace Top25 = 3 if agencydescription == "Raleigh Police Department" replace Top25 = 4 if agencydescription == "Greensboro Police Department" replace Top25 = 5 if agencydescription == "Fayetteville Police Department" replace Top25 = 6 if agencydescription == "Winston-Salem Police Department" replace Top25 = 7 if agencydescription == "High Point Police Department" replace Top25 = 8 if agencydescription == "Durham Police Department" replace Top25 = 9 if agencydescription == "Cary Police Department" replace Top25 = 10 if agencydescription == "Jacksonville Police Department" replace Top25 = 11 if agencydescription == "Concord Police Department" replace Top25 = 12 if agencydescription == "Wilmington Police Department" replace Top25 = 13 if agencydescription == "Wake County Sheriff's Office" replace Top25 = 14 if agencydescription == "Greenville Police Department" replace Top25 = 15 if agencydescription == "Forsyth County Sheriff's Office" replace Top25 = 16 if agencydescription == "Asheville Police Department" replace Top25 = 17 if agencydescription == "Kannapolis Police Department" replace Top25 = 18 if agencydescription == "Burlington Police Department" replace Top25 = 19 if agencydescription == "Hickory Police Department" replace Top25 = 1 if agencydescription == "SHP - Motor Carrier Enforcement Section" replace Top25 = 21 if agencydescription == "Apex Police Department" replace Top25 = 22 if agencydescription == "Mooresville Police Department" replace Top25 = 23 if agencydescription == "Goldsboro Police Department" replace Top25 = 24 if agencydescription == "Gaston County Police Department" replace Top25 = 25 if agencydescription == "Guilford County Sheriff's Office" replace Top25 = 26 if agencydescription == "Gastonia Police Department" drop if investigation_stop == 1 tab race2 gen black = 1 if race2==2 replace black = 0 if black == . gen hispanic = 1 if race2==3 replace hispanic = 0 if hispanic == . gen other = 1 if race2==4 replace other = 0 if other == . gen low_action = 1 if action_level == 1 replace low_action =0 if action_level == 2 | action_level == 3 gen med_action = 1 if action_level == 2 replace med_action =0 if action_level == 1 | action_level == 3 gen high_action = 1 if action_level == 3 replace high_action =0 if action_level == 2 | action_level == 1 replace age = . if age >99 logistic searchoccur black hispanic other gender age contraoccur i.purpose i.dow i.hourfixed i.Top25 if Top25 != . logistic low_action black hispanic other gender age searchoccur_no_ita contraoccur i.purpose i.dow i.hourfixed i.Top25 if Top25 != . logistic med_action black hispanic other gender age searchoccur_no_ita contraoccur i.purpose i.dow i.hourfixed i.Top25 if Top25 != . logistic high_action black hispanic other gender age searchoccur_no_ita contraoccur i.purpose i.dow i.hourfixed i.Top25 if Top25 != . *********************************************** *********************************************** Part B *********************************************** * * Reading in the data for Part B * clear import delimited Analysis\Chapter9_PartB_SearchInfo.csv * cross sectional times searies declaration gen int date = ym(year, month) format date %tm encode agency, gen(encoded_agency) tsset encoded_agency date * Cleaning that data replace stops = "" if stops == "NA" destring stops, replace replace searches = "" if searches == "NA" destring searches, replace replace consentsearches = "" if consentsearches == "NA" destring consentsearches, replace replace probablecausesearches = "" if probablecausesearches == "NA" destring probablecausesearches, replace gen consent_ban = 0 replace consent_ban = 1 if year==2011 & month>8 replace consent_ban = 1 if year==2012 & month<3 replace writtenconsent = "" if writtenconsent == "NA" destring writtenconsent, replace replace leadershipchange = "" if leadershipchange == "NA" destring leadershipchange, replace gen con_rate = (consentsearches/stops)*100 gen pr_rate = (probablecausesearches/stops)*100 * * Figure 9.1 * twoway line consentsearches date if agency == "Fayetteville" & year>2002 & year <2017, scheme(sj) xtitle("Year") graphregion(color(white)) aspectratio() ylabel(, nogrid) xlabel(504 "2002" 516 "2003" 528 "2004" 540 "2005" 552 "2006" 564 "2007" 576 "2008" 588 "2009" 600 "2010" 612 "2011" 624 "2012" 636 "2013" 648 "2014" 660 "2015" 672 "2016",angle(45) axis(1)) xline(620 625 637) graph export Figures_PNG\Figure9_1a.png, width(1950) replace graph export Figures_EPS\Figure9_1a.eps, replace line consentsearches date if agency == "Durham" & year>2002 & year <2017, sort cmissing(n) /// scheme(sj) xtitle("Year") graphregion(color(white)) aspectratio() ylabel(, nogrid) /// xlabel(504 "2002" 516 "2003" 528 "2004" 540 "2005" 552 "2006" 564 "2007" 576 "2008" 588 "2009" 600 "2010" 612 "2011" 624 "2012" 636 "2013" 648 "2014" 660 "2015" 672 "2016",angle(45) axis(1)) /// xline(656 677) graph export Figures_PNG\Figure9_1b.png, width(1950) replace graph export Figures_EPS\Figure9_1b.eps, replace line consentsearches date if agency == "ChapelHill" & year>2002 & year <2017, sort cmissing(n) /// scheme(sj) xtitle("Year") graphregion(color(white)) aspectratio() ylabel(, nogrid) /// xlabel(504 "2002" 516 "2003" 528 "2004" 540 "2005" 552 "2006" 564 "2007" 576 "2008" 588 "2009" 600 "2010" 612 "2011" 624 "2012" 636 "2013" 648 "2014" 660 "2015" 672 "2016",angle(45) axis(1)) /// xline(666) graph export Figures_PNG\Figure9_1c.png, width(1950) replace graph export Figures_EPS\Figure9_1c.eps, replace * * Figure 9.2 * twoway line probablecausesearches date if agency == "Fayetteville" & year>2002 & year <2017, scheme(sj) xtitle("Year") graphregion(color(white)) aspectratio() ylabel(, nogrid) xlabel(504 "2002" 516 "2003" 528 "2004" 540 "2005" 552 "2006" 564 "2007" 576 "2008" 588 "2009" 600 "2010" 612 "2011" 624 "2012" 636 "2013" 648 "2014" 660 "2015" 672 "2016",angle(45) axis(1)) xline(620 625 637) graph export Figures_PNG\Figure9_2a.png, width(1950) replace graph export Figures_EPS\Figure9_2a.eps, replace line probablecausesearches date if agency == "Durham" & year>2002 & year <2017, sort cmissing(n) /// scheme(sj) xtitle("Year") graphregion(color(white)) aspectratio() ylabel(, nogrid) /// xlabel(504 "2002" 516 "2003" 528 "2004" 540 "2005" 552 "2006" 564 "2007" 576 "2008" 588 "2009" 600 "2010" 612 "2011" 624 "2012" 636 "2013" 648 "2014" 660 "2015" 672 "2016",angle(45) axis(1)) /// xline(656 677) graph export Figures_PNG\Figure9_2b.png, width(1950) replace graph export Figures_EPS\Figure9_2b.eps, replace line probablecausesearches date if agency == "ChapelHill" & year>2002 & year <2017, sort cmissing(n) /// scheme(sj) xtitle("Year") graphregion(color(white)) aspectratio() ylabel(, nogrid) /// xlabel(504 "2002" 516 "2003" 528 "2004" 540 "2005" 552 "2006" 564 "2007" 576 "2008" 588 "2009" 600 "2010" 612 "2011" 624 "2012" 636 "2013" 648 "2014" 660 "2015" 672 "2016",angle(45) axis(1)) /// xline(666) graph export Figures_PNG\Figure9_2c.png, width(1950) replace graph export Figures_EPS\Figure9_2c.eps, replace * * Table 9.3 * gen writtenconsent2 = writtenconsent replace writtenconsent2 = 1 if agency == "Durham" & month == 9 & year == 2014 replace writtenconsent2 = 1 if agency == "Fayetteville" & month == 2 & year == 2012 replace writtenconsent2 = 1 if agency == "ChapelHill" & month == 5 & year == 2015 arima consentsearches consent_ban writtenconsent leadershipchange if agency == "Fayetteville", arima(1,0,1) *arima consentsearches consent_ban writtenconsent2 leadershipchange if agency == "Fayetteville", arima(1,0,1) *arima consentsearches writtenconsent leadershipchange if agency == "Durham", arima(4,1,0) arima consentsearches writtenconsent2 leadershipchange if agency == "Durham", arima(4,1,0) arima consentsearches writtenconsent if agency == "ChapelHill", arima(4,0,0) * * Table 9.4 * arima probablecausesearches consent_ban writtenconsent leadershipchange if agency == "Fayetteville", arima(1,1,1) *arima probablecausesearches consent_ban writtenconsent2 leadershipchange if agency == "Fayetteville", arima(1,1,1) *arima probablecausesearches writtenconsent leadershipchange if agency == "Durham", arima(3,1,2) arima probablecausesearches writtenconsent2 leadershipchange if agency == "Durham", arima(3,1,2) arima probablecausesearches writtenconsent if agency == "ChapelHill", arima(0,1,1) *********************************************** *********************************************** Part C *********************************************** * * Reading in the data for Part C * clear import delimited Analysis\Chapter9_PartC_FayeData.csv * Cleaning that data replace arrests = "" if arrests == "NA" destring arrests, replace replace calls = "" if calls == "NA" destring calls, replace replace indicator = "" if indicator == "NA" destring indicator, replace replace indicator = 0 if year < 2011 replace indicator = 1 if year > 2015 replace callsperarrest = "" if callsperarrest == "NA" destring callsperarrest, replace gen int date = ym(year, month) format date %tm tsset date drop if year<2000 * * Figure 9.4 * line callsperarrest date if year>2010 & year<2016, sort cmissing(n) /// scheme(sj) xtitle("Year") graphregion(color(white)) aspectratio() ylabel(, nogrid) /// xlabel(612 "2011" 624 "2012" 636 "2013" 648 "2014" 660 "2015",angle(45) axis(1)) /// xline(620 625 637) graph export Figures_PNG\Figure9_3a.png, width(1950) replace graph export Figures_EPS\Figure9_3a.eps, replace line arrests date if year>2006 & year<2017, sort cmissing(n) /// scheme(sj) xtitle("Year") graphregion(color(white)) aspectratio() ylabel(, nogrid) /// xlabel(612 "2011" 624 "2012" 636 "2013" 648 "2014" 660 "2015",angle(45) axis(1)) /// xline(620 625 637) graph export Figures_PNG\Figure9_3b.png, width(1950) replace graph export Figures_EPS\Figure9_3b.eps, replace * * Table 9.6 * gen consent_ban = 0 replace consent_ban = 1 if year==2011 & month>8 replace consent_ban = 1 if year==2012 & month<3 gen writtenconsent = 0 replace writtenconsent = 1 if indicator>0 replace writtenconsent = 1 if year == 2012 & month == 2 gen leadershipchange = 0 replace leadershipchange = 1 if year>2013 replace leadershipchange = 1 if year==2013 & month >1 arima callsperarrest consent_ban writtenconsent leadershipchange, arima(1,0,1) arima arrests consent_ban writtenconsent leadershipchange, arima(1,0,0) log close