---
title: "Rmd Milanovic CAT"
author: "Nom estudiant"
date: "10/29/2020"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, message = FALSE, warning = FALSE)
library(foreign)
library(tidyr)
library(dplyr)
library(ggplot2)
```

```{r echo = FALSE}
#descargamos
download.file("https://www.gc.cuny.edu/getmedia/514d5ba9-74ed-4007-a3fe-02b079705c91/LM_WPID_web_2",
              "all_ginis.dta", mode = "wb")
```

Creem base de dades `all_ginis`.

```{r}
all_ginis <- as_tibble(read.dta("all_ginis.dta"))
```

Visualitzem marc de dades `all_ginis`.

```{r}
head(all_ginis)
```

L'elefant!

```{r}
all_ginis %>%
  filter(bin_year %in% c(1988, 2008), #filtrem només els anys 1988 i 2008
         !is.na(RRinc)) %>% #eliminem NA
  group_by(ventile_n, bin_year, RRmean_ventile_n) %>% #agrupem per ventil, any i ingrés real
  summarize() %>% #simplifiquem el marc de dades
  spread(bin_year, RRmean_ventile_n) %>% #posem un any a cada columna
  mutate(diff = (`2008` - `1988`) / `1988`) %>% #creem una nova columna amb la diferència d'ingrés real entre 2008 i 1988
  ggplot(aes(x = ventile_n, y = diff)) +
  geom_line() + 
  scale_y_continuous(labels = scales::percent_format(accuracy = 1)) +
  labs(x = "Income group (ventile)", y = "Real income growth (%)") +
  theme_bw()
```


Quants països tenim?

```{r}
unique(all_ginis$country)
```




