Códigos del módulo

En este apartado podéis encontrar los códigos del módulo 3 Indicadores Socioeconómicos.

Indicadores económicos

Para realizar las actividades de este apartado, cargad los siguientes paquetes:

library(tidyverse)
library(readxl)
library(countrycode)
library(devtools)
library(haven)
library(ggmap)
library(unvotes)

1. Medidas de centralidad: ingreso nacional

1.1 Introducción

PIB - Banco 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)) #consultamos países
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 tiempo

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. Medidas de dispersión: desigualdad, riqueza y pobreza

2.2 Desigualdad

World Inequality Database (WID)

library(devtools)
install_github("WIDworld/wid-r-tool")
library(wid)

wid <- download_wid(
   indicators = "sfiinc", #seleccionamos indicador
   areas = c("FR", "CN", "US", "DE", "GB", "RU"), #seleccionamos países
   perc = "p99p100", #seleccionamos 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 Pobreza y riqueza

PovcalNet

library(povcalnetR)

pov <- povcalnet(country = c("MDG", "COG", "RWA"), povline = 1.9) pov %>%
  ggplot(aes(x = year, y = povertygap, col = countryname)) +
  geom_line()

Indicadores sociales

Introducción

World Development Indicators

library(tidyverse)
library(readxl)
library(WDI)

WDIsearch("crime")

crime <- WDI(indicator = "IC.FRM.OBS.OBST6", extra = TRUE) 
unique(crime$region) #miramos las regiones

Un panel de objetivos de desarrollo

SDG Index

library(readxl)
sdg <- read_xlsx("SDR2020Database.xlsx", sheet = 4)
Previous