-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.R
More file actions
59 lines (38 loc) · 2.26 KB
/
models.R
File metadata and controls
59 lines (38 loc) · 2.26 KB
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
##Regression Model
# Remove rows with NA in GDP, Debt, and Revenue & pandemic years (2020-2021) as dummy variable for time fixed effects
cleaned_data <- merged_data %>%
drop_na(GDP, Debt, Revenue)
cleaned_data$pandemic_year <- ifelse(cleaned_data$Year %in% c(2020, 2021), 1, 0)
# Fit the linear model of Debt on GDP
library(plm)
lm_model <- plm(Debt ~ GDP + GDP_Per_Capita,
data = cleaned_data,
index = c("Country_Name", "Year"),
effect = "twoways", # Including both country and time fixed effects
model = "within") # "within" transformation to remove fixed effects
# pandemic_year is perfectly collinear with time fixed effect (thus its coefficient is zero), so it's not included in the equation due to redundancy.
# Extract the coefficient and p-value for GDP to display on the plot
model_summary <- summary(lm_model)
coef_GDP <- coef(model_summary)[1, 1] # Coefficient for GDP
p_value_GDP <- coef(model_summary)[1, 4] # P-value for GDP
print(model_summary)
# Create formatted text to display on the plot
regression_text <- paste("GDP Coef: ", round(coef_GDP, 4), "\n",
"p-value: ", round(p_value_GDP, 4), sep = "")
# Fit the linear model of Debt on Revenue
lm_model_2 <- plm(Debt ~ Revenue + GDP_Per_Capita,
data = cleaned_data,
index = c("Country_Name", "Year"),
effect = "twoways", # Including both country and time fixed effects
model = "within") # "within" transformation to remove fixed effects
# Extract coefficient and p-value from the model to display on the plot
model_summary <- summary(lm_model)
model_summary_2 <- summary(lm_model_2)
coef_value_2 <- coef(model_summary_2)[1, 1] # Coefficient for Revenue
p_value_2 <- coef(model_summary_2)[1, 4] # P-value for Revenue
print(model_summary_2)
# Create a formatted text to display on the plot
regression_text_2 <- paste("Revenue Coef: ", round(coef_value_2, 4),
"\n", "p-value: ", round(p_value_2, 4), sep = "")
#exporting the cleaned_data as csv file to the designated folder
write.csv(cleaned_data, file = "/Users/Lenovo/Documents/GitHub/DAP2-final-project-andiyoga34/Data/Final, clean data/cleaned_data.csv", row.names = FALSE)