library(readr)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(ggplot2)
gdp_data <- read_csv("~/Desktop/Development/GDP_Data/API_NY.GDP.PCAP.PP.KD_DS2_en_csv_v2_23239.csv", skip = 3)
## New names:
## • `` -> `...69`
## Rows: 266 Columns: 69
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (4): Country Name, Country Code, Indicator Name, Indicator Code
## dbl (34): 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, ...
## lgl (31): 1960, 1961, 1962, 1963, 1964, 1965, 1966, 1967, 1968, 1969, 1970, ...
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
# List of country names to include
include_names <- c("Afghanistan", "Albania", "Algeria", "American Samoa", "Andorra", "Angola", "Antigua and Barbuda",
"Argentina", "Armenia", "Aruba", "Australia", "Austria", "Azerbaijan", "Bahamas, The", "Bahrain",
"Bangladesh", "Barbados", "Belarus", "Belgium", "Belize", "Benin", "Bermuda", "Bhutan", "Bolivia",
"Bosnia and Herzegovina", "Botswana", "Brazil", "British Virgin Islands", "Brunei Darussalam",
"Bulgaria", "Burkina Faso", "Burundi", "Cabo Verde", "Cambodia", "Cameroon", "Canada", "Cayman Islands",
"Central African Republic", "Chad", "Channel Islands", "Chile", "China", "Colombia", "Comoros",
"Congo, Dem. Rep.", "Congo, Rep.", "Costa Rica", "Cote d'Ivoire", "Croatia", "Cuba", "Curacao",
"Cyprus", "Czechia", "Denmark", "Djibouti", "Dominica", "Dominican Republic", "Ecuador",
"Egypt, Arab Rep.", "El Salvador", "Equatorial Guinea", "Eritrea", "Estonia", "Eswatini", "Ethiopia",
"Faroe Islands", "Fiji", "Finland", "France", "French Polynesia", "Gabon", "Gambia, The", "Georgia",
"Germany", "Ghana", "Gibraltar", "Greece", "Greenland", "Grenada", "Guam", "Guatemala", "Guinea",
"Guinea-Bissau", "Guyana", "Haiti", "Honduras", "Hong Kong SAR, China", "Hungary", "Iceland", "India",
"Indonesia", "Iran, Islamic Rep.", "Iraq", "Ireland", "Isle of Man", "Israel", "Italy", "Jamaica",
"Japan", "Jordan", "Kazakhstan", "Kenya", "Kiribati", "Korea, Dem. People's Rep.", "Korea, Rep.",
"Kosovo", "Kuwait", "Kyrgyz Republic", "Lao PDR", "Latvia", "Lebanon", "Lesotho", "Liberia", "Libya",
"Liechtenstein", "Lithuania", "Luxembourg", "Macao SAR, China", "Madagascar", "Malawi", "Malaysia",
"Maldives", "Mali", "Malta", "Marshall Islands", "Mauritania", "Mauritius", "Mexico",
"Micronesia, Fed. Sts.", "Moldova", "Monaco", "Mongolia", "Montenegro", "Morocco", "Mozambique",
"Myanmar", "Namibia", "Nauru", "Nepal", "Netherlands", "New Caledonia", "New Zealand", "Nicaragua",
"Niger", "Nigeria", "North Macedonia", "Northern Mariana Islands", "Norway", "Oman", "Pakistan",
"Palau", "Panama", "Papua New Guinea", "Paraguay", "Peru", "Philippines", "Poland", "Portugal",
"Puerto Rico", "Qatar", "Romania", "Russian Federation", "Rwanda", "Samoa", "San Marino",
"Sao Tome and Principe", "Saudi Arabia", "Senegal", "Serbia", "Seychelles", "Sierra Leone", "Singapore",
"Sint Maarten (Dutch part)", "Slovak Republic", "Slovenia", "Solomon Islands", "Somalia",
"South Africa", "South Sudan", "Spain", "Sri Lanka", "St. Kitts and Nevis", "St. Lucia",
"St. Martin (French part)", "St. Vincent and the Grenadines", "Sudan", "Suriname", "Sweden",
"Switzerland", "Syrian Arab Republic", "Tajikistan", "Tanzania", "Thailand", "Timor-Leste", "Togo",
"Tonga", "Trinidad and Tobago", "Tunisia", "Turkiye", "Turkmenistan", "Turks and Caicos Islands",
"Tuvalu", "Uganda", "Ukraine", "United Arab Emirates", "United Kingdom", "United States", "Uruguay",
"Uzbekistan", "Vanuatu", "Venezuela, RB", "Viet Nam", "Virgin Islands (U.S.)", "West Bank and Gaza",
"Yemen, Rep.", "Zambia", "Zimbabwe")
# Select only the required columns and remove specified country codes
gdp_data_2015_2023 <- gdp_data %>%
select(`Country Name`, `Country Code`, `2015`, `2023`) %>%
filter(!is.na(`2015`) & !is.na(`2023`)) %>%
filter(`Country Name` %in% include_names) # Remove rows with specified country codes
View(gdp_data_2015_2023)
gdp_no_Guyana <- gdp_data_2015_2023 %>%
filter(`Country Name` != "Guyana") # Remove rows with specified country codes
View(gdp_no_Guyana)
# Filter to get US GDP in 2015
us_gdp_2015 <- gdp_no_Guyana$`2015`[gdp_no_Guyana$`Country Code` == "USA"]
# GDP in 2015 index
gdp_no_Guyana$GDP_Index_2015 <- (gdp_no_Guyana$`2015` / us_gdp_2015)
# Calculate the AAGR for each country
gdp_no_Guyana$AAGR <- (((gdp_no_Guyana$`2023` / gdp_no_Guyana$`2015`)^(1 / (2023 - 2015)) - 1) * 100)
mean(gdp_no_Guyana$AAGR)
## [1] 1.235357
ggplot(gdp_no_Guyana, aes(x = GDP_Index_2015, y = AAGR)) +
geom_point(color = "blue", size = 3) + # Points for each country
geom_smooth(method = "lm", color = "red", se = TRUE) + # Linear trend line
labs(
x = "GDP Index for 2015 (as ratio of US GDP in 2015)",
y = "Annual Average GDP per capita growth rate (2015-2023)",
caption = "Source: World Bank (2023). GDP per capita (PPP, constant 2021 international $); Guyana excluded. Linear egression with 95% confidence."
) +
annotate("text", x = 1.05, y = min(gdp_no_Guyana$AAGR) - 0.05, label = "--> Larger than US Economy", vjust = 1.5, hjust = 0, size = 5) +
annotate("text", x = 0.95, y = min(gdp_no_Guyana$AAGR) - 0.05, label = "Smaller than US Economy <--", vjust = 1.5, hjust = 1, size = 5) +
theme_minimal() +
theme(
plot.title = element_text(hjust = 0.5, size = 20),
axis.title.x = element_text(size = 18),
axis.title.y = element_text(size = 18),
axis.text = element_text(size = 16),
plot.caption = element_text(size = 10.6, hjust = 0.5, face = "italic", margin = margin(t = 10))
)
## `geom_smooth()` using formula = 'y ~ x'
