-
Notifications
You must be signed in to change notification settings - Fork 0
/
MSc_dissertation_repo.R
353 lines (322 loc) · 8.59 KB
/
MSc_dissertation_repo.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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
---
title: "MSc_Dissertation_Code"
author: "Joe Arber"
date: "16/9/2019"
output: html_document
runtime: shiny
---
###Set up script and working directory###
rm(list = ls())
setwd("~/PUBL0055")
###Install folowing packages if neccessary###
#install.packages("plm") #install.packages("tidyverse") #install.packages("ggmap") #install.packages("mcv") #install.packages('dplyr'
###Load in necessary packages####
library(texreg)
library(foreign)
library(lmtest)
library(plm)
library(boot)
library(car)
##For data cleaning, wrangling and easier manipulation:
library(mice)
#library(tidyverse)
#library(dplyr)
#For data visualisation load:
library(ggplot2)
########## Load in Data ##########
library("readxl")
Dataset2_ <- read_excel("~/Desktop/Dissertation/Dataset2 .xlsx")
Panel1<-Dataset2_
######### Wrangling and Data Management ##########
ls(Panel1)
#Take a look at the structure of the dataset, followed by a summary...
str(Panel1)
summary(Panel1)
dim(Panel1)
head(Panel1$Loans_Chinese)
#Coerce variables to correct types:
str(Panel1)
Panel1$IMF_loans <- as.integer(Panel1$IMF_loans)
Panel1$Received_Chinese_loans <- as.integer(Panel1$Received_Chinese_loans)
str(Panel1)
##Check for missing values
summary(Panel1[c('Govt_Exp','Inflation_annual','GDP_pc','GDP')])
#Count the missing values
sum(is.na(Panel1))
###Alternative to MICE is to replace missing values with average values
Panel1$Inflation_annual[is.na(Panel1$Inflation_annual)] <- mean(Panel1$Inflation_annual, na.rm = TRUE)
Panel1$GDP_pc[is.na(Panel1$GDP_pc)] <- mean(Panel1$GDP_pc, na.rm = TRUE)
Panel1$GDP[is.na(Panel1$GDP)] <- mean(Panel1$GDP, na.rm = TRUE)
Panel1$Govt_Exp[is.na(Panel1$Govt_Exp)] <- mean(Panel1$Govt_Exp, na.rm = TRUE)
Panel1$Central_govt_debt[is.na(Panel1$Central_govt_debt)] <- mean(Panel1$Central_govt_debt, na.rm = TRUE)
Panel1$Loans_WB[is.na(Panel1$Loans_WB)] <- mean(Panel1$Loans_WB, na.rm = TRUE)
sum(is.na(Panel1))
head(Panel1)
#Transformations
LogGDP_PC <- log(Panel1$GDP_pc)
LogGDP <- log(Panel1$GDP)
LogODA <- log(Panel1$Net_ODA)
LogGovExp <- log(Panel1$Govt_Exp)
LogWB <- log(Panel1$Loans_WB)
####GAM Regressions####
library(mgcv)
M1 <-gam(Good_gov ~ s(Inflation_annual, k = 10)
+ Received_Chinese_loans
+ lag(Loans_Chinese)
+ LogGovExp
+ LogODA
+ LogGDP
+ Central_govt_debt
+ Natural_resource
+ Functioning_Gov
+ Jud_indep
+ Freedom_House
+ Media_censorship
+ Internet_censorship,
data = Panel1,
method = "REML",
family = "gaussian",
select = TRUE)
#Model checking
summary.gam(M1)
gam.check(M1)
#Model fit
library(aod)
waldtest2 = wald.test(b = coef(M1), Sigma = vcov(M1), Terms = 1:13)
waldtest2
M2 <-gam(Good_gov ~ s(Urban_pop, k = 10)
+ IMF_loans
+ lag(LogWB)
+ LogGovExp
+ LogODA
+ LogGDP
+ Central_govt_debt
+ Natural_resource
+ Jud_indep
+ Functioning_Gov
+ Freedom_House
+ Media_censorship
+ Internet_censorship,
data = Panel1,
method = "REML",
family = "gaussian",
select = TRUE)
plot(M2, shade = TRUE, shade.col = "lightblue")
M3 <-gam(Control_of_corruption ~ s(Inflation_annual, k = 10)
+ Received_Chinese_loans
+ LogGDP
+ LogGovExp
+ s(Central_govt_debt)
+ Natural_resource
+ Jud_indep
+ Functioning_Gov
+ Freedom_House
+ Media_censorship,
data = Panel1,
method = "REML",
family = "gaussian",
select = TRUE)
M3.1 <-gam(Control_of_corruption ~ s(Inflation_annual, k = 10)
+ IMF_loans
+ LogWB
+ LogGDP
+ LogGovExp
+ s(Central_govt_debt)
+ Natural_resource
+ Jud_indep
+ Functioning_Gov
+ Freedom_House
+ Media_censorship,
data = Panel1,
method = "REML",
family = "gaussian",
select = TRUE)
screenreg(list(M3, M3.1))
coef(M3)
M4 <-gam(Control_of_corruption ~ s(Inflation_annual, k = 10)
+ Chinese_contracts
+ LogGDP
+ LogGovExp
+ s(Central_govt_debt)
+ Natural_resource
+ LogODA
+ Jud_indep
+ Functioning_Gov
+ Freedom_House
+ Media_censorship
+ LogWB,
data = Panel1,
method = "REML",
family = "gaussian",
select = TRUE)
screenreg(M4)
M5 <-gam(Reg_qual ~ s(Inflation_annual, k = 10)
+ Chinese_contracts
+ LogGDP
+ LogGovExp
+ s(Central_govt_debt)
+ Natural_resource
+ LogODA
+ Jud_indep
+ Functioning_Gov
+ Freedom_House
+ Media_censorship
+ LogWB,
data = Panel1,
method = "REML",
family = "gaussian",
select = TRUE)
M5 <-gam(Voice ~ s(Inflation_annual, k = 10)
+ Chinese_contracts
+ LogGDP
+ LogGovExp
+ s(Central_govt_debt)
+ Natural_resource
+ LogODA
+ Jud_indep
+ Functioning_Gov
+ Freedom_House
+ Media_censorship,
data = Panel1,
method = "REML",
family = "gaussian",
select = TRUE)
screenreg(M5)
screenreg(list(M3, M3.1,M4,M5))
htmlreg(list(M3,M3.1),file = "Chinese_corruption1.2.doc")
#Visualization
ggplot(Panel1, aes(x = Chinese_contracts, y = Control_of_corruption)) +
geom_point(
mapping = aes(x = Chinese_contracts, y = Control_of_corruption, color = Received_Chinese_loans)) +
scale_x_log10() +
stat_smooth(method = "gam", formula = y ~ s(x,k=10))
####(PLM) Fixed Effects Models####
Fixed_effects1 <- plm (Good_gov ~ Received_Chinese_loans
+ Loans_Chinese
+ LogGDP
+ LogODA
+ LogGovExp
+ Inflation_annual
+ Central_govt_debt
+ Functioning_Gov
+ Jud_indep
+ Natural_resource
+ Urban_pop
+ Internet_censorship,
data = Panel1,
index = c("Country", "Year"),
effect = "individual")
summary(Fixed_effects1)
screenreg(Fixed_effects1)
Fixed_effects2 <- plm (Good_gov ~ IMF_loans
+ lag(LogWB)
+ lag(LogGDP)
+ LogODA
+ LogGovExp
+ Inflation_annual
+ Central_govt_debt
+ Functioning_Gov
+ Jud_indep
+ Natural_resource
+ Urban_pop
+ Internet_censorship,
data = Panel1,
index = c("Country", "Year"),
effect = "individual")
Fixed_effects3 <- plm (Control_of_corruption ~ Received_Chinese_loans
+ lag(Loans_Chinese)
+ lag(LogGDP)
+ LogGovExp
+ Central_govt_debt
+ Functioning_Gov
+ Voice
+ Jud_indep
+ Freedom_House
+ Natural_resource
+ Urban_pop
+ Internet_censorship,
data = Panel1,
index = c("Country", "Year"),
effect = "time")
Fixed_effects4 <- plm (Control_of_corruption ~ IMF_loans
+ lag(LogWB)
+ lag(LogGDP)
+ LogGovExp
+ Central_govt_debt
+ Functioning_Gov
+ Voice
+ Jud_indep
+ Freedom_House
+ Natural_resource
+ Urban_pop
+ Internet_censorship,
data = Panel1,
index = c("Country", "Year"),
effect = "individual")
Fixed_effects5 <- plm (Control_of_corruption ~ Chinese_contracts
+ lag(LogWB)
+ lag(LogGDP)
+ LogGovExp
+ Central_govt_debt
+ Functioning_Gov
+ Voice
+ Jud_indep
+ Freedom_House
+ Natural_resource
+ Urban_pop
+ Internet_censorship,
data = Panel1,
index = c("Country", "Year"),
effect = "time")
Fixed_effects6 <- plm (Reg_qual ~ Chinese_contracts
+ lag(LogWB)
+ lag(LogGDP)
+ LogGovExp
+ Central_govt_debt
+ Functioning_Gov
+ Voice
+ Jud_indep
+ Freedom_House
+ Natural_resource
+ Urban_pop
+ Internet_censorship,
data = Panel1,
index = c("Country", "Year"),
effect = "individual")
screenreg(list(Fixed_effects1, Fixed_effects2, Fixed_effects3, Fixed_effects4, Fixed_effects5, Fixed_effects6))
htmlreg(list(Fixed_effects1, Fixed_effects2, Fixed_effects3, Fixed_effects4, Fixed_effects5, Fixed_effects6),file = "Appendix_Fixed_effects.doc")
#Test for the prescence of country effects
plmtest(Fixed_effects1, effect ="individual")
#Test for serial correlation in the error term
pbgtest(Fixed_effects1)
#Correction for serial correlation
FE_1_hac <- coeftest(
Fixed_effects1,
vcov = vcovHC(Fixed_effects1, method = "arellano", type = "HC3")
)
#Test for cross-sectional dependence
pcdtest(Fixed_effects1)
#The cross-sectional and serial correlation (SCC) method by Driscoll and Kraay for obtaining heteroskedasticity and autocorrelation consistent errors that are also robust to cross-sectional dependence
FE_scc <- coeftest(
Fixed_effects1,
vcov = vcovSCC(Fixed_effects1, type="HC3", cluster = "group")
)
FE_scc
screenreg(
list(Fixed_effects1, FE_1_hac, FE_scc),
custom.model.names = c("Fixed Effects", "Fixed Effects (HAC)","Fixed Effects (SCC)")
)
#Control variable plots
ggplot(data = Panel1) + geom_point (mapping = aes (x=Urban_pop, y=Good_gov))
ggplot(data = Panel1) + geom_point (mapping = aes (x=LogGDP_PC, y=Good_gov))
ggplot(data = Panel1) + geom_point (mapping = aes (x=LogODA, y=Good_gov))
ggplot(data = Panel1) + geom_point (mapping = aes (x=Oil_rent, y=Good_gov))
ggplot(data = Panel1) + geom_point (mapping = aes (x=Central_govt_debt, y=Good_gov))
ggplot(data = Panel1) + geom_point (mapping = aes (x=Media_censorship, y=Good_gov))
ggplot(data = Panel1) + geom_point (mapping = aes (x=Internet_censorship, y=Good_gov))
ggplot(data = Panel1) + geom_point (mapping = aes (x=Natural_resource, y=Good_gov))
ggplot(data = Panel1) + geom_point (mapping = aes (x=Freedom_House, y=Good_gov))
ggplot(data = Panel1) + geom_point (mapping = aes (x=Jud_indep, y=Good_gov))
ggplot(data = Panel1) + geom_point (mapping = aes (x=Loans_WB, y=Good_gov))
ggplot(data = Panel1) + geom_point (mapping = aes (x=LogGovExp, y=bci_bci))
ggplot(data = Panel1) + geom_point (mapping = aes (x=Inflation_annual, y=Good_gov))