-
Notifications
You must be signed in to change notification settings - Fork 0
/
euGrants.R
296 lines (243 loc) · 11.1 KB
/
euGrants.R
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
library(curl)
library(dplyr)
library(tidyr)
library(readxl)
library(ggplot2)
# function to fill in na from next row
fillNa <- function(x) {
lstval <- NA
for (i in seq_along(x)) {
ifelse(is.na(x[i]), x[i] <- lstval, lstval <- x[i])
}
x
}
# Download Files ----------------------------------------------------------
# # (need to download 2015 separately as it's in xlsx)
# for(i in 2007:2014) {
# curl::curl_download(paste0("http://ec.europa.eu/budget/remote/fts/dl/export_",i,"_en.xls"),
# destfile = paste0("euFunds/funds",i,".xls"))
# }
#
# curl::curl_download("http://ec.europa.eu/budget/remote/fts/dl/export_2015_en.xlsx",
# destfile = "euFunds/funds2015.xlsx")
#
files = list.files("data/euFunds/", full.names = T)
# merge files -------------------------------------------------------------
# (use fillNA to fill missings for shared contracts)
# df1 <- readxl::read_excel(files[1])
# names(df1)[12] <- "Total amount"
# df1 <- df1 %>% dplyr::select(-Coordinator, -`Geographical Zone`, -`Co-financing rate`) %>%
# dplyr::mutate(Amount = as.numeric(Amount))
#
# df2 <- readxl::read_excel(files[2])
# names(df2)[12] <- "Total amount"
# df2 <- df2 %>% dplyr::select(-Coordinator, -`Geographical Zone`, -`Co-financing rate`) %>%
# dplyr::mutate(Amount = as.numeric(Amount))
#
# df3 <- readxl::read_excel(files[3])
# names(df3)[12] <- "Total amount"
# df3 <- df3 %>% dplyr::select(-Coordinator, -`Geographical Zone`, -`Co-financing rate`) %>%
# dplyr::mutate(Amount = as.numeric(Amount))
df4 <- readxl::read_excel(files[4]) %>%
dplyr::select(-Coordinator, -`VAT Number of beneficiary`,
-`Geographical Zone`, -`Co-financing rate`) %>%
dplyr::mutate(Amount = ifelse(is.na(Amount), `Total amount`, Amount)) %>%
dplyr::mutate_each(funs(fillNa(.)), -`Name of beneficiary`, -Address,
-City, -`Postal code`, -`Country / Territory`, -Amount, -`Total amount`)
df5 <- readxl::read_excel(files[5]) %>%
dplyr::select(-Coordinator, -`VAT Number of beneficiary`,
-`Geographical Zone`, -`Co-financing rate`) %>%
dplyr::mutate(Amount = ifelse(is.na(Amount), `Total amount`, Amount)) %>%
dplyr::mutate_each(funs(fillNa(.)), -`Name of beneficiary`, -Address,
-City, -`Postal code`, -`Country / Territory`, -Amount, -`Total amount`)
df6 <- readxl::read_excel(files[6]) %>%
dplyr::select(-Coordinator, -`VAT Number of beneficiary`,
-NUTS2, -`Geographical Zone`, -`Co-financing rate`) %>%
dplyr::mutate(Amount = ifelse(is.na(Amount), `Total amount`, Amount)) %>%
dplyr::mutate_each(funs(fillNa(.)), -`Name of beneficiary`, -Address,
-City, -`Postal code`, -`Country / Territory`, -Amount, -`Total amount`)
df7 <- readxl::read_excel(files[7]) %>%
dplyr::select(-Coordinator, -`VAT Number of beneficiary`,
-`Geographical Zone`,-NUTS2) %>%
dplyr::mutate(Amount = ifelse(Amount==0, `Total amount`, Amount)) %>%
dplyr::mutate_each(funs(fillNa(.)), -`Name of beneficiary`, -Address,
-City, -`Postal code`, -`Country / Territory`, -Amount, -`Total amount`)
df8 <- readxl::read_excel(files[8]) %>%
dplyr::select(-Coordinator, -`VAT Number of beneficiary`,
-`Geographical Zone`,-NUTS2) %>%
dplyr::mutate(Amount = ifelse(is.na(Amount), `Total amount`, Amount)) %>%
dplyr::mutate_each(funs(fillNa(.)), -`Name of beneficiary`, -Address,
-City, -`Postal code`, -`Country / Territory`, -Amount, -`Total amount`)
df9 <- readxl::read_excel(files[9]) %>%
dplyr::select(-Coordinator, -`VAT Number of beneficiary`,
-`Geographical Zone`,-NUTS2) %>%
dplyr::mutate(Year = as.numeric(Year)) %>%
dplyr::mutate(Amount = ifelse(is.na(Amount), `Total amount`, Amount)) %>%
dplyr::mutate_each(funs(fillNa(.)), -`Name of beneficiary`, -Address,
-City, -`Postal code`, -`Country / Territory`, -Amount, -`Total amount`)
df <- dplyr::full_join(df4, df5) %>%
dplyr::full_join(., df6) %>%
dplyr::full_join(., df7) %>%
dplyr::full_join(., df8) %>%
dplyr::full_join(., df9)
# Tables and Figures ------------------------------------------------------
# dictionaries
schools <- c("UNIVERSITY", "UNIVERSITE", "SCHOOL", "COLLEGE",
"UNIVERSIT", "SCHULE")
medicine <- c("HOSPITAL","Medical","Medicine", "KLINIKUM", "MEDIZIN",
"PHARMA", "MEDISCH")
department <- c("Research", "Education", "Innovation")
# Subsets
universities <- df %>%
dplyr::filter(grepl("Grant",
`Funding Type`, ignore.case = T)) %>%
dplyr::filter(grepl(paste(department, collapse = "|"),
`Responsible Department`,ignore.case = T)) %>%
dplyr::filter(grepl(paste(schools, collapse = "|"),
`Name of beneficiary`,ignore.case = T)) %>%
dplyr::filter(!grepl(paste(medicine, collapse = "|"),
`Name of beneficiary`,ignore.case = T))
germany <- df %>%
dplyr::filter(`Country / Territory`=="Germany") %>%
dplyr::filter(grepl("Grant",
`Funding Type`, ignore.case = T)) %>%
dplyr::filter(grepl(paste(department, collapse = "|"),
`Responsible Department`,ignore.case = T)) %>%
dplyr::filter(grepl(paste(schools, collapse = "|"),
`Name of beneficiary`,ignore.case = T)) %>%
dplyr::filter(!grepl(paste(medicine, collapse = "|"),
`Name of beneficiary`,ignore.case = T))
uk <- df %>%
dplyr::filter(`Country / Territory`=="United Kingdom") %>%
dplyr::filter(grepl("Grant",
`Funding Type`, ignore.case = T)) %>%
dplyr::filter(grepl(paste(department, collapse = "|"),
`Responsible Department`,ignore.case = T)) %>%
dplyr::filter(grepl(paste(schools, collapse = "|"),
`Name of beneficiary`,ignore.case = T)) %>%
dplyr::filter(!grepl(paste(medicine, collapse = "|"),
`Name of beneficiary`,ignore.case = T))
hertie <- df %>%
dplyr::filter(grepl("Grant",
`Funding Type`, ignore.case = T)) %>%
dplyr::filter(grepl("Hertie School",
`Name of beneficiary`, ignore.case = T))
# Top German Universities
topgerFund <- germany %>% dplyr::group_by(`Name of beneficiary`) %>%
dplyr::summarise(round(sum(Amount))) %>%
dplyr::arrange(desc(`round(sum(Amount))`))
topgerCase <- germany %>% dplyr::group_by(`Name of beneficiary`) %>%
dplyr::summarise(n())
topger <- dplyr::full_join(topgerFund, topgerCase) %>%
dplyr::arrange(desc(`round(sum(Amount))`))
write.csv(topger, file = "topger.csv")
# Top UK Universities
topukFund <- uk %>% dplyr::group_by(`Name of beneficiary`) %>%
dplyr::summarise(round(sum(Amount))) %>%
dplyr::arrange(desc(`round(sum(Amount))`))
topukCase <- uk %>% dplyr::group_by(`Name of beneficiary`) %>%
dplyr::summarise(n())
topuk <- dplyr::full_join(topukFund, topukCase) %>%
dplyr::arrange(desc(`round(sum(Amount))`))
write.csv(topuk, file = "topuk.csv")
# Compare Ger to UK
gerYears <- germany %>% dplyr::group_by(Year) %>%
dplyr::summarise(sum(Amount))
gerCases <- germany %>% dplyr::group_by(Year) %>%
dplyr::summarise(n())
gerAmount <- dplyr::full_join(gerYears, gerCases)
ukYears <- uk %>% dplyr::group_by(Year) %>%
dplyr::summarise(sum(Amount))
ukCases <- uk %>% dplyr::group_by(Year) %>%
dplyr::summarise(n())
ukAmount <- dplyr::full_join(ukYears, ukCases)
hertieAmount <- hertie %>%
dplyr::mutate(`EU Grants` = n()) %>%
dplyr::mutate(`EU Funding` = sum(Amount)) %>%
dplyr::mutate(Type = "Hertie") %>%
select(`EU Grants`, `EU Funding`, Type) %>%
dplyr::filter(!duplicated(.))
# Top Business Schools
Copenhagen <- universities %>%
dplyr::filter(grepl("COPENHAGEN BUSINESS SCHOOL",
`Name of beneficiary`, ignore.case = T)) %>%
dplyr::summarise(sum(Amount))
LUISS <- universities %>%
dplyr::filter(grepl("LUISS",
`Name of beneficiary`, ignore.case = T)) %>%
dplyr::summarise(sum(Amount))
Maastricht <- universities %>%
dplyr::filter(grepl("Maastricht",
`Name of beneficiary`, ignore.case = T)) %>%
dplyr::summarise(sum(Amount))
Corvinus <- universities %>%
dplyr::filter(grepl("Corvinus",
`Name of beneficiary`, ignore.case = T)) %>%
dplyr::summarise(sum(Amount))
CEU <- universities %>%
dplyr::filter(grepl("BUDAPESTI KOZEP",
`Name of beneficiary`, ignore.case = T)) %>%
dplyr::summarise(sum(Amount))
Carlo <- df %>%
dplyr::filter(grepl("COLLEGIO CARLO ALBERTO",
`Name of beneficiary`, ignore.case = T)) %>%
dplyr::summarise(sum(Amount))
Essex <- df %>%
dplyr::filter(grepl("Grant",
`Funding Type`, ignore.case = T)) %>%
dplyr::filter(grepl("University of Essex",
`Name of beneficiary`, ignore.case = T)) %>%
dplyr::summarise(sum(Amount))
# Think Tanks
OpenEvidence <- df %>%
dplyr::filter(grepl("Open Evidence",
`Name of beneficiary`, ignore.case = T)) %>%
dplyr::summarise(sum(Amount))
Wuppertal <- df %>%
dplyr::filter(grepl("WUPPERTAL INSTITUT FUR KLIMA",
`Name of beneficiary`, ignore.case = T)) %>%
dplyr::summarise(sum(Amount))
ispi <- df %>%
dplyr::filter(grepl("ISTITUTO PER GLI STUDI",
`Name of beneficiary`, ignore.case = T)) %>%
dplyr::summarise(sum(Amount))
ids <- df %>%
dplyr::filter(grepl("Institute of Development Studies",
`Name of beneficiary`, ignore.case = T)) %>%
dplyr::summarise(sum(Amount))
pse <- df %>%
dplyr::filter(grepl("FONDATION DE COOPERATION SCIENTIFIQUE ECOLE D",
`Name of beneficiary`, ignore.case = T)) %>%
dplyr::summarise(sum(Amount))
# Data Projects
data <- df %>%
dplyr::filter(grepl("Grant",
`Funding Type`, ignore.case = T)) %>%
dplyr::filter(grepl(paste(department, collapse = "|"),
`Responsible Department`,ignore.case = T)) %>%
dplyr::filter(grepl("data",`Subject of grant or contract`, ignore.case = T)) %>%
dplyr::filter(!duplicated(`Subject of grant or contract`))
sobigdata <- df %>%
dplyr::filter(grepl("SOBIGDATA",
`Subject of grant or contract`, ignore.case = T)) %>%
dplyr::summarise(sum(Amount))
sense4us <- df %>%
dplyr::filter(grepl("Data Insights for Policy Makers",
`Subject of grant or contract`, ignore.case = T)) %>%
dplyr::summarise(sum(Amount))
quantess <- df %>%
dplyr::filter(grepl("Quantitative Analysis of Textual Data",
`Subject of grant or contract`, ignore.case = T)) %>%
dplyr::summarise(sum(Amount))
cessda <- df %>%
dplyr::filter(grepl("cessda",
`Subject of grant or contract`, ignore.case = T)) %>%
dplyr::summarise(sum(Amount))
datactive <-df %>%
dplyr::filter(grepl("DATACTIVE",
`Subject of grant or contract`, ignore.case = T)) %>%
dplyr::summarise(sum(Amount))
DELECA <- df %>%
dplyr::filter(grepl("leadership capacity",
`Subject of grant or contract`, ignore.case = T)) %>%
dplyr::summarise(sum(Amount))