-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_casualty_data.Rmd
175 lines (138 loc) · 5.42 KB
/
get_casualty_data.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
---
title: "Extension of Findley and Young (2015)"
author: "Soo Wan Kim"
date: "March 14, 2017"
output: word_document
---
```{r setup, include=FALSE}
#import packages
library(rmarkdown)
library(knitr)
library(tidyverse)
library(lubridate)
library(haven)
```
# Duration
## All Terrorism
```{r duration_all_terr, eval=FALSE}
#import list of COW country codes by country name
cow <- read.csv("data/COW country codes.csv")
cow <- unique(cow) %>%
rename(cowcode = CCode) #standardize country code var to facilitate merges
#import GTD
gtd <- read.csv("Data/gtd.csv")
#list of target types to exclude from analysis of civilian casualties
exclude <- c("Government (Diplomatic)", "Police", "Military", "Government (General)",
"Terrorists/Non-State Militia", "Tourists", "Violent Political Party",
"Unknown")
#filter GTD to include only year, month, country code, target type, and number killed
gtd_filt <- gtd %>%
select(iyear, imonth, country, targtype1, targtype1_txt, nkill) %>%
#standardize variables for merging
rename(year = iyear, month = imonth, cowcode = country) %>%
#distinguish between civilian-targeting attacks and non-civilian targeting attacks
mutate(civilian = ifelse(targtype1_txt %in% exclude, "not civilian", "civilian")) %>%
na.omit() #remove NAs
#############################
#Attacks targeting civilians#
#############################
#get count of civilian deaths by month for each year
gtd_civ_cas_month <- gtd_filt %>%
filter(civilian == "civilian") %>%
group_by(year, month, cowcode) %>%
#take log of number of civilian deaths + 1
summarize(lnterr_civcas_month = log(sum(nkill) + 1))
#######################
#All terrorist attacks#
######################
#get count of total deaths by month for each year
gtd_tot_cas_month <- gtd_filt %>%
group_by(year, month, cowcode) %>%
#take log of number of deaths + 1
summarize(lnterr_totcas_month = log(sum(nkill) + 1))
#combine civilian deaths and total deaths
gtd_cas_month <- left_join(gtd_tot_cas_month, gtd_civ_cas_month)
#export to .dta file
write_dta(gtd_cas_month, "gtd_cas_month.dta")
```
## Suicide Terrorism
```{r duration_suicide_terr, eval=FALSE}
#############################
#Attacks targeting civilians#
#############################
#import SAD for attacks targeting civilians
suicide_civtarg <- read.csv("Data/cpost_civilian_target.csv") %>%
rename(StateNme = location_names) #standardize country name
suicide_civtarg$attack_date <- as.Date(suicide_civtarg$attack_date)
#add country codes
suicide_civtarg <- left_join(suicide_civtarg, cow, by="StateNme")
#remove NAs and create month and year columns for merging with FY2015 data
suicide_civtarg <- suicide_civtarg %>%
na.omit() %>%
mutate(year = year(attack_date),
month = month(attack_date))
#get log of civilian casualties + 1 each country-month from suicide terrorist attacks
suicide_civtarg_count <- suicide_civtarg %>%
group_by(cowcode, year, month) %>%
summarize(lnsui_civcas_month = log(sum(number_killed) + 1))
suicide_civtarg_count$cowcode <- as.numeric(suicide_civtarg_count$cowcode)
#######################
#All terrorist attacks#
######################
#import SAD for all attacks
suicide_total <- read.csv("Data/cpost_all_target.csv") %>%
rename(StateNme = location_names)
suicide_total$attack_date <- as.Date(suicide_total$attack_date)
#add country codes
suicide_total <- left_join(suicide_total, cow, by="StateNme")
#remove NAs and standardize month and year variable names
suicide_total <- suicide_total %>%
na.omit() %>%
mutate(year = year(attack_date),
month = month(attack_date))
#get log of total casualties + 1 each country-month from suicide terrorist attacks
suicide_total_count <- suicide_total %>%
group_by(cowcode, year, month) %>%
summarize(lnsui_totcas_month = log(sum(number_killed) + 1))
suicide_total_count$cowcode <- as.numeric(suicide_total_count$cowcode)
#combine civilian deaths and total deaths
suicide_cas_month <- left_join(suicide_total_count, suicide_civtarg_count)
#export to .dta
write_dta(suicide_cas_month, "suicide_cas_month.dta")
```
# Recurrence
## All Terrorism
```{r recurrence_all_terr, eval=FALSE}
#get log of count of civilian deaths + 1 from terrorist attacks for each country-year
gtd_civ_cas_year <- gtd_filt %>%
filter(civilian == "civilian") %>%
group_by(year, cowcode) %>%
summarize(lnterr_civcas_year = log(sum(nkill) + 1))
#get log of count of total deaths + 1 for each country-year
gtd_tot_cas_year <- gtd_filt %>%
group_by(year, cowcode) %>%
summarize(lnterr_totcas_year = log(sum(nkill) + 1))
#combine civilian deaths and total deaths
gtd_cas_year <- left_join(gtd_tot_cas_year, gtd_civ_cas_year)
#export to .dta
write_dta(gtd_cas_year, "gtd_cas_year.dta")
```
## Suicide Terrorism
```{r recurrence_suicide_terr, eval=FALSE}
#get log of count of civilian and total deaths + 1
#from suicide terrorist attacks for each country-year
suicide_cas_year <- suicide_cas_month %>%
#move backwards from monthly casualty data to get raw counts for each month
mutate(sui_civcas_month = exp(lnsui_civcas_month) - 1,
sui_totcas_month = exp(lnsui_totcas_month) - 1) %>%
select(-lnsui_totcas_month, -lnsui_civcas_month) %>%
group_by(cowcode, year) %>%
#take logs
summarize(lnsui_civcas_year = log(sum(sui_civcas_month) + 1),
lnsui_totcas_year = log(sum(sui_totcas_month) + 1))
#export to .dta
write_dta(suicide_cas_year, "suicide_cas_year.dta")
```
```{r include=FALSE}
devtools::session_info()
```