Codis del mòdul
En aquest apartat hi podeu trobar els codis del mòdul 4 Indicadors Socioeconòmics.
Indicadors econòmics
Per realitzar les activitats d’aquest apartat, carregueu d’inici els següents paquets:
library(tidyverse)
library(readxl)
library(countrycode)
library(devtools)
library(haven)
library(ggmap)
library(unvotes)
1. Mesures de centralitat: ingrés nacional
1.1 Introducció
PIB - Banc Mundial
library(wbstats)
wb_search("gdp")%>%
View()
wb_search("gdp.*capita")%>%
View()
gdp <- wb_data(country = "countries_only",
return_wide = TRUE,
indicator = c("NY.GDP.PCAP.CN")) %>%
mutate(date = as.numeric(date)) %>% as_tibble()
sort(unique(gdp$country)) #consultemos països
gdp %>%
filter(country %in% c("Poland", "Switzerland")) %>%
ggplot(aes(x = date, y = NY.GDP.PCAP.CN, col = country)) +
geom_line()
1.2 A través del temps
Maddison Historical Data
library(haven)
mad <- read_dta("https://www.rug.nl/ggdc/historicaldevelopment/maddison/data/mpd2020.dta")
mad %>%
filter(country %in% c("France", "Zambia", "Chad"),
year %in% c(1, 1789, 2000)) %>%
transmute(País = countrycode(country, "country.name.en", "cldr.name.ca"),
Any = year, PIBcap = round(gdppc), Pop = round(pop))
2. Mesures de dispersió: desigualtat, riquesa i pobresa
2.2 Desigualtat
World Inequality Database (WID)
library(devtools)
install_github("WIDworld/wid-r-tool")
library(wid)
wid <- download_wid(
indicators = "sfiinc", #seleccionem indicador
areas = c("FR", "CN", "US", "DE", "GB", "RU"), #seleccionem països
perc = "p99p100", #seleccionem percentil
) %>% as_tibble()
wid %>%
ggplot(aes(x = year, y = value, col = country)) +
geom_point(alpha = 0.2) +
geom_smooth(se = FALSE)
All Ginis
all_ginis <- haven::read_dta("https://www.gc.cuny.edu/getmedia/514d5ba9-74ed-4007-a3fe-02b079705c91/LM_WPID_web_2")
all_ginis %>%
filter(bin_year %in% c(1988, 2008), !is.na(RRinc)) %>%
group_by(ventile_n, year, RRmean_ventile_n) %>%
summarize() %>%
spread(year, RRmean_ventile_n) %>%
mutate(diff = (`2008` - `1988`) / `1988`) %>%
ggplot(aes(x = ventile_n, y = diff)) +
geom_line()
2.3 Pobresa i riquesa
PovcalNet
library(povcalnetR)
pov <- povcalnet(country = c("MDG", "COG", "RWA"), povline = 1.9) pov %>%
ggplot(aes(x = year, y = povertygap, col = countryname)) +
geom_line()