---
title: "Revenu universel de base avec le retrait de l'exemption fiscale de base"
output: html_document
---

## Obtenir les informations pertinentes sur les revenus canadiens depuis Statistiques Canada

```{r}
library(statcanR)
library(dplyr)
library(stringr)
library(readr)
```

```{r}
# Population by income group
population_by_income_group <- statcanR::statcan_download_data(tableNumber="98-10-0064-01", lang="eng")
```
Cleaning total income column names

```{r}
names(population_by_income_group) <- c("REF_DATE","GEO","DGUID","AGE","GENDER","TOTAL_INCOME_GROUP", "COORDINATE","Y2020","SYMBOL0","Y2015","SYMBOL","INDICATOR","COORDINATE0")
```


Cleaning total income population data

```{r}
population_by_income_group %>%
  filter(GEO=="Canada", 
         AGE=="Total - Age", 
         GENDER=="Total - Gender") %>%
  select(REF_DATE,TOTAL_INCOME_GROUP,Y2020,Y2015)->
  population_by_income_group_filtered
```


```{r}
# Population by after-tax income group
population_by_after_tax_income_group <- statcanR::statcan_download_data(tableNumber="98-10-0065-01", lang="eng")
```
Cleaning after tax column names

```{r}
names(population_by_after_tax_income_group) <- c("REF_DATE","GEO","DGUID","AGE","GENDER","AFTERTAX_INCOME_GROUP", "COORDINATE","Y2020","SYMBOL0","Y2015","SYMBOL","INDICATOR","COORDINATE0")
```

Cleaning after tax population data

```{r}
population_by_after_tax_income_group %>%
  filter(GEO=="Canada", 
         AGE=="Total - Age", 
         GENDER=="Total - Gender") %>%
  select(REF_DATE,AFTERTAX_INCOME_GROUP,Y2020,Y2015)->
  population_by_after_tax_income_group_filtered
```

Save data to csv file

```{r}
population_by_income_group_filtered %>%
  write_csv("population_by_income_group_filtered.csv")
population_by_after_tax_income_group_filtered %>% 
  write_csv("population_by_after_tax_income_group_filtered.csv")
```


```{r}
# Tax brackets
federal_income_brackets <- read.csv("federal-income-brackets.csv")
```
