-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathASEAN_FDI.Rmd
393 lines (296 loc) · 12.8 KB
/
ASEAN_FDI.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
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
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
---
title: "Final project"
author: "Pranandita & Risolat"
date: "08/01/2024"
output:
html_document:
code_folding: hide
---
```{css, echo=FALSE}
.scroll-200 {
max-height: 200px;
overflow-y: auto;
background-color: inherit;
}
h1, h2, h3 {
text-align: center;
}
```
```{r message=FALSE, warning=FALSE, include=FALSE}
library(knitr)
library(kableExtra)
library(ggplot2)
library(dplyr)
library(questionr)
library(dplyr)
library(ggpmisc)
library(broom)
library(tinytex)
library(stargazer)
library(sandwich)
library(readr)
library(readxl)
library(tidyverse)
library(plm)
library(corrplot)
library(Hmisc)
library(lmtest)
library(corrplot)
library(ggResidpanel)
```
```{r}
data <- read_excel("New_DATA.xlsx")
```
### Correlation matrix
<p style="text-align:center;"> __Linear variables:__ </p>
```{r, results='asis', message=FALSE, warning=FALSE, fig.align = 'center'}
corr_data <- select(data, fdi, ps, gdp, gdp_g, cpi, t_o)
corr_data <- na.omit(corr_data)
corr_matrix <- cor(corr_data)
kable(corr_matrix, format = "html", caption = "Correlation matrix") %>%
kable_styling(full_width = FALSE)
corrplot(corr_matrix)
```
\
<p style="text-align:center;"> __With log(FDI) and log(GDP):__ </p>
```{r, results='asis', message=FALSE, warning=FALSE, fig.align = 'center'}
corr_data <- corr_data %>%
mutate(log_fdi = log(fdi), log_gdp = log(gdp)) %>%
select(-fdi, -gdp)
corr_data <- na.omit(corr_data)
corr_matrix <- cor(corr_data)
kable(corr_matrix, format = "html", caption = "Correlation matrix") %>%
kable_styling(full_width = FALSE)
corrplot(corr_matrix)
```
### Regressions
Here, we present separately the regressions of FDI on political stability with real GDP, growth rate, CPI, and trade openness as controls. We use log of FDI and real GDP; all other variables are linear.
We add the independent and control variables one by one to the model and then perform pooled OLS and random and fixed effects regressions for each set of variables. For each, we perform the BPLM test (`pFtest`) to check for panel effects. Next, we perform the Hausman test (`phtest`) to decide between fixed and random effects models.
The results are summarized separately for each set of models along with significance levels of all test statistics.
```{r, results='asis', message=FALSE, warning=FALSE}
## only political stability
# pooled OLS
pols1 = lm(log(fdi) ~ ps, data = data)
# fixed effects
f1 <- plm(log(fdi) ~ ps, index = c("country", "year"), data = data, model = "within")
#random effects
r1 <- plm(log(fdi) ~ ps, index = c("country", "year"), data = data, model = "random")
# Hausman test
h1_stat <- round(phtest(f1, r1)$statistic, 2)
h1_p <- round(phtest(f1, r1)$p.value, 4)
# Breusch-Pagan LM test
bplm1_stat <- round(pFtest(f1, pols1)$statistic, 2)
bplm1_p <- sprintf("%.2e", pFtest(f1, pols1)$p.value)
# Regression output #1
stargazer(pols1, f1, r1,
title="Regressions on FDI - only political stability (independent variable)",
type="html",
header=FALSE,
report = "vc*s",
dep.var.labels = c("FDI"),
column.labels = c("Pooled OLS", "Fixed effects", "Random effects"),
covariate.labels = c("Intercept", "Political stability"),
add.lines = list(
c("BPLM (FE)", "", "", ""),
c("statistic", bplm1_stat, "", ""),
c("p-value", bplm1_p, "", ""),
c("Hausman", "", "", ""),
c("statistic", h1_stat, "", ""),
c("p-value", h1_p, "", "")
),
intercept.bottom = F,
digits = 2,
notes.align = "l",
notes = c("Dataset: World Bank Database", "lm() functions"))
## political stability + gdp as control
# pooled OLS
pols2 = lm(log(fdi) ~ ps + log(gdp), data = data)
# fixed effects
f2 <- plm(log(fdi) ~ ps + log(gdp), index = c("country", "year"), data = data, model = "within")
#random effects
r2 <- plm(log(fdi) ~ ps + log(gdp), index = c("country", "year"), data = data, model = "random")
# Hausman test
h2_stat <- round(phtest(f2, r2)$statistic, 2)
h2_p <- round(phtest(f2, r2)$p.value, 4)
# Breusch-Pagan LM test
bplm2_stat <- round(pFtest(f2, pols2)$statistic, 2)
bplm2_p <- sprintf("%.2e", pFtest(f2, pols2)$p.value)
# Regression output #2
stargazer(pols2, f2, r2,
title="Regressions on FDI - political stability (independent variable) + real GDP as control",
type="html",
header=FALSE,
report = "vc*s",
dep.var.labels = c("FDI"),
column.labels = c("Pooled OLS", "Fixed effects", "Random effects"),
covariate.labels = c("Intercept", "Political stability", "Log(GDP)"),
add.lines = list(
c("BPLM (FE)", "", "", ""),
c("statistic", bplm2_stat, "", ""),
c("p-value", bplm2_p, "", ""),
c("Hausman", "", "", ""),
c("statistic", h2_stat, "", ""),
c("p-value", h2_p, "", "")
),
intercept.bottom = F,
digits = 2,
notes.align = "l",
notes = c("Dataset: World Bank Database", "lm() functions"))
## political stability + gdp, growth as controls
# pooled OLS
pols3 = lm(log(fdi) ~ ps + log(gdp) + gdp_g, data = data)
# fixed effects
f3 <- plm(log(fdi) ~ ps + log(gdp) + gdp_g, index = c("country", "year"), data = data, model = "within")
#random effects
r3 <- plm(log(fdi) ~ ps + log(gdp) + gdp_g, index = c("country", "year"), data = data, model = "random")
# Hausman test
h3_stat <- round(phtest(f3, r3)$statistic, 2)
h3_p <- round(phtest(f3, r3)$p.value, 4)
# Breusch-Pagan LM test
bplm3_stat <- round(pFtest(f3, pols3)$statistic, 2)
bplm3_p <- sprintf("%.2e", pFtest(f3, pols3)$p.value)
# Regression output #3
stargazer(pols3, f3, r3,
title="Regressions on FDI - political stability (independent variable) + real GDP and growth rate as controls",
type="html",
header=FALSE,
report = "vc*s",
dep.var.labels = c("FDI"),
column.labels = c("Pooled OLS", "Fixed effects", "Random effects"),
covariate.labels = c("Intercept", "Political stability", "Log(GDP)", "Growth rate"),
add.lines = list(
c("BPLM (FE)", "", "", ""),
c("statistic", bplm3_stat, "", ""),
c("p-value", bplm3_p, "", ""),
c("Hausman", "", "", ""),
c("statistic", h3_stat, "", ""),
c("p-value", h3_p, "", "")
),
intercept.bottom = F,
digits = 2,
notes.align = "l",
notes = c("Dataset: World Bank Database", "lm() functions"))
## political stability + gdp, growth, cpi as controls
# pooled OLS
pols4 = lm(log(fdi) ~ ps + log(gdp) + gdp_g + cpi, data = data)
# fixed effects
f4 <- plm(log(fdi) ~ ps + log(gdp) + gdp_g + cpi, index = c("country", "year"), data = data, model = "within")
#random effects
r4 <- plm(log(fdi) ~ ps + log(gdp) + gdp_g + cpi, index = c("country", "year"), data = data, model = "random")
# Hausman test
h4_stat <- round(phtest(f4, r4)$statistic, 2)
h4_p <- round(phtest(f4, r4)$p.value, 4)
# Breusch-Pagan LM test
bplm4_stat <- round(pFtest(f4, pols4)$statistic, 2)
bplm4_p <- sprintf("%.2e", pFtest(f4, pols4)$p.value)
stargazer(pols1, f4, r4,
title="Regressions on FDI - political stability (independent variable) + real GDP, growth, and CPI as controls",
type="html",
header=FALSE,
report = "vc*s",
dep.var.labels = c("FDI"),
column.labels = c("Pooled OLS", "Fixed effects", "Random effects"),
covariate.labels = c("Intercept", "Political stability", "Log(GDP)", "Growth rate", "CPI"),
add.lines = list(
c("BPLM (FE)", "", "", ""),
c("statistic", bplm4_stat, "", ""),
c("p-value", bplm4_p, "", ""),
c("Hausman", "", "", ""),
c("statistic", h4_stat, "", ""),
c("p-value", h4_p, "", "")
),
intercept.bottom = F,
digits = 2,
notes.align = "l",
notes = c("Dataset: World Bank Database", "lm() functions"))
## political stability + gdp, growth, cpi, trade openness as controls
# pooled OLS
pols5 = lm(log(fdi) ~ ps + log(gdp) + gdp_g + cpi + t_o, data = data)
# fixed effects
f5 <- plm(log(fdi) ~ ps + log(gdp) + gdp_g + cpi + t_o, index = c("country", "year"), data = data, model = "within")
#random effects
r5 <- plm(log(fdi) ~ ps + log(gdp) + gdp_g + cpi + t_o, index = c("country", "year"), data = data, model = "random")
# Hausman test
h5_stat <- round(phtest(f5, r5)$statistic, 2)
h5_p <- round(phtest(f5, r5)$p.value, 4)
# Breusch-Pagan LM test
bplm5_stat <- round(pFtest(f5, pols5)$statistic, 2)
bplm5_p <- round(pFtest(f5, pols5)$p.value, 4)
# Regression output #5
stargazer(pols5, f5, r5,
title="Regressions on FDI - political stability (independent variable) + real GDP, growth, CPI, and trade openness as controls",
type="html",
header=FALSE,
report = "vc*s",
dep.var.labels = c("FDI"),
column.labels = c("Pooled OLS", "Fixed effects", "Random effects"),
covariate.labels = c("Intercept", "Political stability", "Log(GDP)", "Growth rate", "CPI", "Trade openness"),
add.lines = list(
c("BPLM (FE)", "", "", ""),
c("statistic", bplm5_stat, "", ""),
c("p-value", bplm5_p, "", ""),
c("Hausman", "", "", ""),
c("statistic", h5_stat, "", ""),
c("p-value", h5_p, "", "")
),
intercept.bottom = F,
digits = 2,
notes.align = "l",
notes = c("Dataset: World Bank Database", "lm() functions"))
```
### Final results
Based on the results of the BPLM and Hausman tests, we choose the appropriate model specification for each set of independent and control variables. The final results of the chosen models are summarized here.
```{r, results='asis', message=FALSE, warning=FALSE}
stargazer(r1, r2, f3, r4, f5,
title="Final models",
type="html",
header=FALSE,
report = "vc*s",
dep.var.labels = c("FDI"),
column.labels = c("Model #1", "Model #2", "Model #3", "Model #4", "Model #5"),
covariate.labels = c("Intercept", "Political stability", "Log(GDP)", "Growth rate", "CPI", "Trade openness"),
add.lines = list(
c("", "Random", "Random", "Fixed", "Random", "Fixed"),
c("BPLM", paste(as.character(bplm1_stat),"***"), paste(as.character(bplm2_stat),"***"), paste(as.character(bplm3_stat),"***"), paste(as.character(bplm4_stat),"***"), paste(as.character(bplm5_stat),"**")),
c("Hausman", h1_stat, h2_stat, paste(as.character(h3_stat),"**"), h4_stat, paste(as.character(h5_stat),"**"))
),
intercept.bottom = F,
digits = 2,
notes.align = "l",
notes = c("Dataset: World Bank Database", "lm() functions"))
```
### Testing assumptions
We test here the Gauss-Markov assumptions for the selected model: Model #4 (`log(fdi) ~ ps + log(gdp) + gdp_g + cpi`).
```{r, results='asis', message=FALSE, warning=FALSE}
## BPLM
bp <- bptest(f4)
bp_stat <- round(bptest(f4)$statistic, 2)
bp_p <- round(bptest(f4)$p.value, 4)
## Wooldridge test
wooldridge <- pbgtest(f4)
wooldridge_stat <- round(pbgtest(f4)$statistic, 2)
wooldridge_p <- round(pbgtest(f4)$p.value, 4)
```
\
The following table presents the results of tests performed to verify assumptions.
```{r, results='asis', message=FALSE, warning=FALSE}
assumptions_table <- data.frame(
Assumption = c("Homoskedasticity", "No autocorrelation", "Exogeneity", "No spherical errors"),
Test = c("Breusch-Pagan Lagrangian multipliers", "Wooldridge serial correlation", "Hausman", "Breusch-Pagan Lagrangian multipliers"),
Statistic = c(bp_stat, wooldridge_stat, h4_stat, bp_stat),
p = c(bp_p, wooldridge_p, h4_p, bp_p),
Satisfied = c("Yes", "Yes", "Yes", "Yes")
)
assumptions_table %>%
kable(caption = "Gauss--Markov assumption tests") %>%
kable_classic(full_width = F, html_font = "Cambria")
```
As none of the test statistics are signficant, we conclude that the assumptions are satisfied.
\
To test for the no multicollinearity assumption, we create the correlation matrix of the coefficients of the regression.
```{r, results='asis', message=FALSE, warning=FALSE}
## Multicollinearity: Correlation matrix
correlation_matrix <- cor(f4$model[, -1])
kable(correlation_matrix, format = "markdown")
```
As none of the coefficients are $>|0.6|$, we conclude that there are no significant multicollinearities that may affect our results.