***** DESIGNATE THE TOP FOLDER WHERE THIS REPLICATION CODE AND THE ASSOCIATED REPLICATION DATA ARE STORED
cd // XXXXX

set more off
pause on // this matters only for sumstats.do
capture log close
clear all
set maxvar 6000
set matsize 5000
log using Spamann, replace
capture mkdir results



***********************************
*** macro definitions *************

* this section defines some globals to be used in the individual do-files below; the locals are building blocks for the globals (makes changes easier to implement throughout)

global imputations=200 										// this will work for some do files but in most I still work with numbers, not the global

global	drugs		" cocaine ecstasy opiates "
global	ICVS		" victim9 C01A100 C06A100 C10A100 C09A100 C12A100 "
global	ICVSnames	`"Overall "Car theft" Burglary Theft Robbery Assault"'

** independent variables incl. table descriptions
global	binary		" legor_uk legor_so fedccp democracy " 	// this is special because (a) hard to impute, and (b) different interaction term in LASSO
															// "legor..." missing for PSP MNP (hardly any data anyway); "fedccp" missing for 20 others, but they have few other $imputables
local	gdp			rgdpl2									// "rgdp" missing for AND LIE MCO MMR NRU PRK TUV
global	loggdp		ln_rgdpl2
global	otherindispensable "propdem i_free"					// "propdem" is always missing if "democracy" is missing; "free" missing for BMU HKG MAC PRI but probably not MAR;
								
local	pastdata	"i_chprtpct i_chcatpct i_isgenpct slave_total250k adekw_ef i_migrants i_urban" // these have data now and earlier
local	nopastdata	"ms1519_pop i_L25teenshare fp_gini wb_db_laborfire_2008 unempl_total_ILO" // teenshare: nothing before 1980s, little before 1990s
															// wb_: measured in 2008 and very time-variable (consider, e.g., transition countries over 1990s)
															// unempl_ILO not available before 1991; national measures not before 1980 and rare in 1990s where UNCTS available
															// note that time variation in p_gini before 1990s is imputed from UTIP; additional data from fp_gini would omit time variation
															// ms: sparse in 1970s and 1980s, in particular for the countries that have UNCTS data (N<20 or so)
															// adekw and slave: also measured only once, but presumably sufficiently stable
local	subpastdata	"p_gini combo_ms1519"					// to be used instead of nopastdata
															
* main varlists
local	notimputable "`gdp' $loggdp $binary $otherindispensable"
global	notimputable : list retokenize notimputable
global	imputable	"`pastdata' `nopastdata'"
global	historical	"`pastdata' `subpastdata'"				// for use instead of $imputable only with UNCTS data in timetrends.do

global	variabledescriptions `" USA "USA dummy" rgdpl2 "GDP per capita" ln_rgdpl2 "ln(GDP per capita)" legor_uk "English legal origin" legor_so "Socialist legal origin" i_isgenpct "Muslim/pop." i_chcatpct  "Catholic/pop." i_chprtpct "Protestant/pop." adekw_ef "Ethnic fractionalization" slave_total250k "Slave descendants/pop." i_free "Freedom" democracy "Democracy" propdem "Proportional voting" fedccp "Federal state" i_migrants "Immigrants/pop." i_urban "Urban/pop." ms1519_pop "Males 15-19/pop." i_L25teenshare "Teen/total births (t-25)" fp_gini "Gini" i_UTIPgini "Gini (UTIP)" wb_db_laborfire_2008 "Difficulty firing worker" unempl_total_ILO "Unemployment rate" "'



**********************************
*** call of do files  ********

**** creating imputation data sets (for MI)
do MI_dataset_creation.do		// main data (prisoners and homicides)
do MI_dataset_drugs_creation.do	// drugs
do MI_dataset_ICVS_creation.do	// ICVS

**** tables & figures

do sumstats.do			// tables 1 & 2 (need to copy output as table & paste into Excel file -- program pauses for that purpose) 
do MI.do				// table 3; figures 1, 2. Notes:
									// 1) in table 3, FIML (equations 4 and 8) is output separately because FIML doesn't work with esttab -- need to combine these by hand
									// 2) the do-file also produces output with classical (non-robust) standard errors for comparison
									// 3) the do-file also creates an Excel file to calculate the contributions of individual US characteristics to predicted difference from OECD mean (for section 4.1)
									// 4) the do-file also creates a scatter plot of raw homicide and incarceration rates in LEVELS (cf. end of introduction's first paragraph)
do ICVS_MI.do 			// table 4 (+ additional results with survey-specific US dummies)
do Drugs_MI.do 			// table 5
do state.do				// figure 3 (OECD v US states); also state regressions for discussion part (section 6.2.3)

do timetrends.do 		// figures 4 and 5 (time trends, raw and residuals)
do bounds.do			// figure 6 & various calculations discussed in section 5.2

**** robustness checks & additional tests for discussion part

do LASSO.do				// cf. section 4.2.2 (robustness check a la Belloni et al., REStud 2014)
do institutionalized.do // cf. section 6.2.1
do guns.do				// cf. section 6.2.2
* section 3.3 / 4.1 (robust standard errors?): see note 2 to MI.do above
* section 4.1 (influence of individual variables): see note 3 to MI.do above
* section 6.2.3: see state.do above

clear
log close
