-
Notifications
You must be signed in to change notification settings - Fork 0
/
script-background-wgi-indicators.R
83 lines (71 loc) · 2.57 KB
/
script-background-wgi-indicators.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
# Start
# title: "Background on United Nations Conventions and World Governance Indicators (WGI)"
# author: "Raquel Baeta"
# date: "2024-07-25"
# Set working directory
setwd("~/Desktop/working-sessions/regression")
# Load data
data <- read_csv("~/Desktop/working-sessions/cleaning_data/cleaned_data.csv")
print(data)
# Calculate mean WGI score
data <- data %>%
rowwise() %>%
mutate(
mean_WGI = mean(c(CC.EST, GE.EST, RQ.EST, RL.EST, VA.EST, PV.EST), na.rm = TRUE))
# Intervals and labels
data$year_interval_3yr <- cut(
data$year,
breaks = seq(1996, 2019, by = 3),
include.lowest = TRUE,
labels = c("1996-1998", "1999-2001", "2002-2004", "2005-2007", "2008-2010", "2011-2013", "2014-2016")
)
# Group data by Country averages
governance_data <- data %>%
group_by(
region, code, country, any_UN, UN1961, UN1971, UN1988) %>%
summarize(
mean_seizures = mean(seizures, na.rm = TRUE),
mean_CC.EST = mean(CC.EST, na.rm = TRUE),
mean_GE.EST = mean(GE.EST, na.rm = TRUE),
mean_RQ.EST = mean(RQ.EST, na.rm = TRUE),
mean_RL.EST = mean(RL.EST, na.rm = TRUE),
mean_VA.EST = mean(VA.EST, na.rm = TRUE),
mean_PV.EST = mean(PV.EST, na.rm = TRUE),
mean_WGI.EST = mean(mean_WGI, na.rm = TRUE)
)
# Time series analysis
governance_data_time_series <- data %>%
group_by(
region, year_interval_3yr) %>%
summarize(
mean_seizures = mean(seizures, na.rm = TRUE),
mean_CC.EST = mean(CC.EST, na.rm = TRUE),
mean_GE.EST = mean(GE.EST, na.rm = TRUE),
mean_RQ.EST = mean(RQ.EST, na.rm = TRUE),
mean_RL.EST = mean(RL.EST, na.rm = TRUE),
mean_VA.EST = mean(VA.EST, na.rm = TRUE),
mean_PV.EST = mean(PV.EST, na.rm = TRUE),
mean_WGI.EST = mean(mean_WGI, na.rm = TRUE)
)
# Filter and write CSV files for different regions
regions <- c("East Asia & Pacific", "Europe & Central Asia", "Latin America & Caribbean", "Middle East & North Africa", "North America",
"South Asia", "Sub-Saharan Africa")
for (region in regions) {
filtered_data <- filter(
governance_data_time_series, region == region)
write.csv(
filtered_data,
paste0("filtered_", gsub(" ", "_", tolower(region)), "_wgi.csv"),
row.names = FALSE)
print(summary(filtered_data$mean_WGI.EST))
print(summary(filtered_data$mean_CC.EST))
print(summary(filtered_data$mean_GE.EST))
print(summary(filtered_data$mean_RQ.EST))
print(summary(filtered_data$mean_RL.EST))
print(summary(filtered_data$mean_VA.EST))
print(summary(filtered_data$mean_PV.EST))
}
# Print and summarize US data
us_rows <- data %>% filter(code == "USA")
print(us_rows, n = 21)
# End