Untitled

R script
 avatar
user_4897320
markdown
a month ago
2.3 kB
1
Indexable
Never

title: "IntMacroResearchHW" author: "Ruben Sahakyan" date: "2024-05-20" output: pdf_document

knitr::opts_chunk$set(echo = TRUE)
library(WDI)
library(tidyverse)
library(ggplot2)
# Download data for Armenia, Azerbaijan, and Georgia
data <- WDI(indicator = c('NY.GDP.PCAP.PP.KD',  # GDP per capita, PPP (constant 2011 international $)
                          "BN.CAB.XOKA.GD.ZS",  # Current account balance (% of GDP)
                          "IC.BUS.DFRN.XQ",     # Ease of doing business index (1=most business-friendly regulations)
                          "FP.CPI.TOTL.ZG",     # Inflation, consumer prices (annual %)
                          "FR.INR.LNDP"),       # Lending interest rate (%)
            country = c('ARM', 'AZE', 'GEO'), 
            start = 1994, 
            end = 2022)
# Extract GDP and labor indicators for Armenia, Azerbaijan, and Georgia
indicators <- c("NY.GDP.PCAP.KD", "NY.GDP.PCAP.PP.KD", "NY.GDP.PCAP.CD", "NY.GDP.PCAP.PP.CD", 
                "NY.GDP.MKTP.KD.ZG", "NY.GDP.PCAP.KD.ZG", "SL.TLF.CACT.ZS", "SL.UEM.TOTL.ZS",
                "BX.KLT.DINV.WD.GD.ZS", "BX.TRF.PWKR.DT.GD.ZS", "NY.GNS.ICTR.ZS", 
                "NE.GDI.TOTL.ZS", "GC.TAX.TOTL.GD.ZS", "GC.TAX.YPKG.ZS", "NE.TRD.GNFS.ZS")

countries <- c("ARM", "AZE", "GEO")

data <- WDI(country = countries, indicator = indicators, start = 1994, end = 2022)
# Filter data for the chosen year and specific indicator
chosen_year <- 2022
indicator <- "BX.KLT.DINV.WD.GD.ZS"
investment_data <- data %>%
  filter(year == chosen_year) %>%
  select(country = iso2c, FDI = !!sym(indicator))  # Ensure iso2c or country name matches map data
# World map preparation and merging
world_map <- map_data("world")
world_data <- left_join(world_map, investment_data, by = c("region" = "country"))
# Plotting FDI on a world map
ggplot() +
  geom_polygon(data = world_data, aes(x = long, y = lat, group = group, fill = FDI), color = "white") +
  scale_fill_gradient(low = "blue", high = "red", na.value = "gray50") +
  labs(title = "FDI (% of GDP) in 2022", fill = "FDI (% of GDP)") +
  theme_minimal()
Leave a Comment