Replication instructions for "Tug of War: The Heterogeneous Effects of Outbidding between Terrorist Groups"
Conducting constrained maximum likelihood estimation (CMLE) requires specialized (open source) software that we are only able to run using the Ubuntu Linux operating system. We provide detailed setup instructions below. All results were produced on a computer using Ubuntu 20.04.6 (Focal Fossa) using R 4.4.1 ("Race for Your Life") and Python 3.8.10. The entire archive should require no more than 2 GB of available RAM, but we recommend a machine with at least 4GB to be safe.
Files marked with (U) require Ubuntu, with the setup as described below.
-
Basic Information
-
readme.mdplain text readme (this file) -
readme.pdfThis document in pdf format -
replicateMainText.sh(U) Reproduces all results in the main text using the code files below in order. Tables and Figures are produced and placed in the Output folder. -
replicateAppendix.sh(U) Reproduces all results in the Appendix using the code files below in order. Tables and Figures are produced and placed in the Output folder -
replicateAll.sh(U) Runs both of the above replication scripts in order.
-
-
Installation
-
pyopt_setup_python3.sh(U) A bash script designed to be run on a fresh installation of Ubuntu 20.04.6. It should also work on the live version or on existing Ubuntu 20.04.6 installations, but this is not tested. This file will install all the necessary outside software to replicate the results (Internet connection is required). -
Rpackages.rAn R script that installs all theRpackages used here with the versions used here. -
sources.listA sources file needed to replace the existing sources file if using a "live" version of Ubuntu 20.04.6 (see below)
-
-
Data: These are both the original data used in the analysis as well as the merged and complete versions used in the analysis.
-
acosta1993.csvAcosta and Ramos' (2017) data to supplement missing data from the Global Terrorism Database (GTD). -
actionsSetup.RdataProduced bybuildDataSets.r, below, aggregates the GTD data to monthly level. This produces the main measurement of the actions -
actionsSetup_byAttackType.RdataContains terrorism data for each group, disaggregated by attack targets. Produced bybuildDataSets_byAttackType.r, below. -
corruption_WBG.csvWorld Bank attitudes towards corruption data for the Palestinian Territories. -
cpsr.csvSurvey data from CPSR/PCPSR. -
cpsr_GAZA.csvSurvey data from CPSR/PCPSR, disaggregated to just the Gaza Strip -
cpsr_WB.csvSurvey data from CPSR/PCPSR, disaggregated to just the West Bank -
ExtraFactors.rdataOutput from the latent measurement model for unemployment status and attitudes towards violence. Produced byappendixD_latentMeasures.r, below. -
gadm41_PSE.gpkgSpatial administrative lines file used to assess the location of the West Bank and Gaza Strip for rainfall data. -
gtd.rdataTerrorist attacks data from the GTD. -
jmcc.csvSurvey data from JMCC -
jmcc_2023.csvSurvey data from JMCC, with additional details collected later in the analysis -
jmcc_GAZA.csvSurvey data from JMCC, disaggregated to just the Gaza Strip -
jmcc_WB.csvSurvey data from JMCC, disaggregated to just the West Bank -
measurement.rdataThe results of the measurement model that produces the latent state variable$\tilde{s}^t$ . Produced bymeasurementModel.r, below -
mortality_WB.csvInfant mortality data for the Palestinian Territories from the World Bank -
otherattacks.rdataPalestinian Islamic Jihad (PIJ) attacks data from the GTD, produced byappendixD_PIJatacks.r, below -
palestinian_deaths_2000_2008.csvPalestinian fatalities data from B'Tselem (2000-2008) -
palestinian_deaths_2008_2020.csvPalestinian fatalities data from B'Tselem (2008-2020) -
PalestinianDeaths.rdataAggregated data on Palestinian fatalities from B'Tselem. Created byappendixD_aggregateDeaths.r, below -
rainData.rdataAggregated data on extreme rainfall in the Palestinian territories from the Global Precipitation Climatology Centre (GPCC) and provided by NOAA. Created byappendixD_buildraindata.r, below
-
-
Code
- Python3 (U)
-
attackProbs.pyGenerate attack probabilities from values -
estFunctions_NoComp.pyEstimation functions for the no competition model -
estFunctions.pyEstimation functions for the main model -
estFunctions_t4t.pyEstimation functions for the tit-for-tat model -
fitChangingDeltas.pyFit the model with different discount factors -
fitMainModel.pyFit the main model -
fitMainModel_t4t.pyFit the tit-for-tat model -
fitNoCompetition.pyFit the no competition model -
fitSensitivity.pyFit the main model, but designed for parallel use -
genGiven.pyHelper function for the estimation functions -
usaParam.pyGenerate utilities from parameter and data -
usaParam_t4t.pyGenerate utilities from parameter and data for the tit-for-tat model
-
- R4.4.1
- Results: A folder of results that are saved and used along the way, but are not directly included in the paper or appendix.
-
appendixB.RThe numerical examples in Appendix B. Produces Figures B.1--4 -
appendixB_equilibiraSearch.RSearches for different solutions to the numerical example. We do not recommend actually running this. -
appendixC_alternatives.rConsider alternatives to the main measurement model. Produces Tables C.3--4 -
appendixC_geographic.RConsiders the geographical differences in the survey responses. Produces Figure C.2 -
appendixD_aggregateDeaths.rAggregates Palestinian fatalities from B'Tselem. CreatesPalestinianDeaths.rdata -
appendixD_buildraindata.rDownloads rainfall data (1.2GB) from GPCC and produces the measures of extreme rainfall in the Palestinian Territories. CreatesrainData.rdata -
appendixD_latentMeasures.rFits the latent measurement model for unemployment status and attitudes towards violence. CreatesExtraFactors.rdata. -
appendixD_PIJattacks.rAggregates PIJ attacks. Producesotherattacks.rdata -
appendixD_robustness.rFits the robustness checks in Appendix D along with the sensitivity analysis. Produces Tables D.1--7 and Figure D.1. -
appendixF.r(U) Fits the simulations in Appendix F. Produces Figure F.1 -
appendixG_VAR_comparison.rFits the Vector Autoregression models in Appendix G. Produces Table G.4 and Figure G.1. -
appendixH.r(U) Fits the model at different temporal subsets. Produces Table H.1. -
appendixI.r(U) Fits the model with different discount factors. Produces Table I.1 and Figure I.1. -
appendixJ1.r(U) Fits the model with different discretization parameters. Produces Table J.1 -
appendixJ2.rFits the model with very coarse discretization parameters. Produces Table J.2 and Figures J.1--2. -
appendixK.RAnalyses and interprets$\beta$ . Produces Figure K.1 -
buildDataSets.rMerges and aggregates the polling and terrorist attack data. ProducesactionsSetup.Rdataand Figure A.1 -
buildDataSets_byAttackType.rMerges and aggregates the polling and terrorist attack data but breaks it down by target type. ProducesactionsSetup_byAttackType.Rdata -
counterfactual_beta.RConducts counterfactual analysis on changes in the value of popularity ($\beta$ ). Produces Figure A.3. -
counterfactual_gamma.RConducts counterfactual analysis on changes the ability to affect popularity ($\gamma$ ). Produces Figure 6. -
counterfactual_kappa.RConducts counterfactual analysis on changes in the costs of terrorism ($\kappa$ ). Produces Figure A.4 -
counterfactual_kappa_discussion.RConducts counterfactual analysis on changes in the costs of terrorism ($\kappa$ ). Produces Table 5. -
counterfactual_single_agent.RConducts the counterfactual comparisons with the single agent models. Produces Figure 5 and Table 4. -
firststageboot.rFunction for a parametric bootstrap on the first stage -
firstStageEstimation.rFit the first stage model. Produces Table 1 -
fitNoCompetition.r(U) Fit the no competition model -
gamma2trans.RFunction to produce the Markov transition matrix from the first-stage results -
graphAttackProbs.RProduces Figures 3 and 4 -
helperFunctions.rVarious helper functions -
helper_functions_t4t.RVarious helper functions for the tit-for-tat model -
liml.rFunctions for limited information maximum likelihood estimators (LIML) for IV regression -
measurementModel.rUses the polling data to produce the continuous version of the state space. Producesmeasurement.rdata, Figures 1--2, and Tables C.2-3. -
secondStageEstimation.r(U) Fits the second stage model. Produces Table 2. -
secondStageEstimation_t4t.r(U) Fits the tit-for-tat model.
- Python3 (U)
-
Output
- Figures. A folder containing all the produced figures
- Tables. A folder containing all the produced tables in text format
The software setup currently uses Ubuntu 20.04.6. To install operating system
- Download iso file and use it to create a "bootable" flash drive
- The iso image can be obtained at this link.
- Instructions for creating a bootable flash drive can be found here (Mac) or here (Windows).
- Insert the flash drive and power on the computer
- Enter the machine's boot menu by pressing the appropriate key repeatedly (the button to activate the boot menu varies with computer make and models -- common keys include F12 (DELL, Most ACERs), F8 (Most ASUS), ESC (HP and some ASUS).
- Select the option to boot from the flash drive USB
- Select "install." WARNING: this will require you to format all or part of your hard drive so don't do it if you don't want that. You can also do a dual boot or live, but we only vouch for and fully support for installation.
- Download the replication package (scroll your cursor to the upper left corner where it says "Activities" and then select the Firefox icon to access the internet)
If trying to use a live version Ubuntu, you should make the following adjustments.
- Replace the live versions sources.list file with the one provided here. This can be accomplished using running the following shell command from the main replication folder
sudo mv sources.list /etc/apt/sources.listThis should be down between steps 3 and 4 in the replication instructions, below.
WARNINGS
- We did not test the live version and do not support it beyond what is listed here.
- Live versions store the OS in active memory, reducing what RAM is available for actual use. This means that the available memory for replication will be noticeably less than the computer's listed specs.
Another alternative that should work is the Windows sub-system for Linux (WSL). This is probably the easiest approach for Windows users and should work. However, we do not vouch for it and haven't tested it.
From a fresh installation of Ubuntu 20.04.6, you will need to use the following steps to prepare the replication environment.
- Download the replication package
- Extract the replication package to the desired location (
${REPDIR}) - Open a terminal and navigate to Installation directory (
${REPDIR}/Installation) - Run the file
pyopt_setup_python3.shusing the command
bash pyopt_setup_python3.shThis step may take up an hour depending on network speed and you may be prompted to press "Enter" at one or more points in the process. As software is downloaded, updated, or installed you may notice various background notifications appearing. These are normal and can be ignored.
A known bug sometimes appears where the installation hangs on "Pregenerating ConTeXt MarkIV format. This may take some time..." If you find yourself here for more than five minutes, press "Enter" 4--5 times and wait about another minute. This will often work to "unstick" it (see this link).
- Run the file
Rpackages.R
Rscript Rpackages.R- We are now ready to produce the results
Any file can be run and will produce the desired output as listed in its description. Two additional script files are provided to replicate the main paper and the appendix, respectively. These call the scripts, in order, to produce the files in the Output folder. Once the above installation is complete, these can be run by opening the terminal in this folder and running
nohup bash replicateMainText.sh & or
nohup bash replicateAppendix.sh &respectively.
Note the use of nohup allows you to let these run in the background for as long as needed. This can be useful if you're replicating this on a remote device. Tables and Figures will be exported to the correct folders and any on-screen text will be collected within the file nohup.out.
Alternatively, the command
nohup bash replicateAll.sh &will run both of the above order.
Finally, note that some of code files in the main text replication file also produce results for the appendix (e.g., some of Appendix G is actually produced by modelFit.r).
Replicating just the main text results takes roughly 40 minutes on an ASUS laptop with 4GB RAM with an Intel i3-5020U (4 threads).
Replicating the appendix without Appendix F takes roughly one day on the same machine. Replicating Appendix F takes roughly a week on this machine, but the code in appendixF.r is parallelized and timing improves in the number of available cores.
If the output in nohup.out text contains the phrase "killed" or outputs are missing in the output folder, then there is likely a memory problem. This can be due to either using a live version that eats up RAM or otherwise having insufficient available memory. Close all other applications (i.e., everything but the terminal running the code) and try again. If there are still issues, try upgrading to a higher memory machine or switching to a real installation rather than a live version. This is most likely to occur when building the two-step corrected standard errors in fitMainModel.py and creating Table 2.