---
title: "Assignment 7: Colonial History"
author: ""
date: ""
output:
  tufte::tufte_handout: 
    highlight: tango 
    df_print: kable
link-citations: yes
editor_options: 
  chunk_output_type: console
---

```{r setup, include=FALSE}
library(tufte)
# invalidate cache when the tufte version changes
knitr::opts_chunk$set(tidy = FALSE, cache.extra = packageVersion('tufte'))
options(htmltools.dir.version = FALSE)
```

\noindent Created: `r Sys.Date()`

\noindent Due Date: 

# Instructions

Prepare a presentation on the effect of colonial infrastructure and institutions on contemporary outcomes. Each slide should have a scatter plot for all SSA countries, a regression line, and a clear indication of your country on the graph.

- Slide 1: Provide a colonial history of your country (dates of colonization and colonizing country).

- Slide 2: Present a graph of political inclusion of locals and contemporary political liberalization. Plot the first year of elected native representation on the x-axis and the Polity score in 1992 on the y-axis.

- Slide 3: Present a graph of the number of physicians per 1,000 people in 1960 (on the x-axis) and life expectancy at birth in 1992 (on the y-axis).

- Slide 4: Present a graph of the rate of tertiary education among 20 to 29-year-olds from 1960 to 1965 (on the x-axis) and life expectancy at birth in 1992 (on the y-axis). Your country may not be represented on this graph. If you can find data for your country, show whether it would be on/above/below the trend line. If you can’t, then use the graph without your country to comment on the general trend.

- Slide 5: Interpret slides 2-4; how did variation in colonial policies impact future development in general, and for your country?


***


# 1. Preparation

If you completed any of the previous problem sets, the `tidyverse` package should already be installed on your computer. If not, run this code chunk. 

```{r eval = FALSE}
install.packages("tidyverse")
```

Similarly, if you haven't installed the `gghighlight` package, do so by running this code chunk.

```{r eval = FALSE}
install.packages("gghighlight")
```

Now, load both packages:

```{r message=FALSE, warning=FALSE}
library(tidyverse)
library(gghighlight)
```

Finally, load the data set from the URL provided. 

```{r message = FALSE}
africa_df <- read_csv('https://african-states-book.info/img/portfolio/problem-sets/data/07-data.csv')
```

As usual, you'll need to assign your country name and your country's ISO 3-character code to the following variables. The `my_country` variable will be used to label plots, while the `my_iso_code` variable will be used to uniquely identify your country in the data set. 

```{r}
my_country <- "Kenya"
my_iso_code <- "KEN"
```

Here is the data for your country:

```{r}
africa_df %>% filter(iso3c == my_iso_code)
```


***


# 2. Political Inclusion and Political Liberalization

Now that the data is prepared, we'll make a scatter plot of the relationship between political inclusion (using the gap between independence and the first year of elected native representation) and political liberalization (measured by the Polity score in 1992). We'll also highlight the position of your country relative to the rest of Sub-Saharan Africa. 

Recall that Polity scores are not defined for countries experiencing state failure. For those countries, we'll use imputed values from the `polity2` variable. Countries governed by multiple colonial administrations (i.e. Cameroon and Somalia) will have multiple dates of first native representation.

```{r message=FALSE, warning=FALSE}
ggplot(africa_df, aes(x = native.rep.yr, y = polity2, label = iso3c)) +
  geom_text(size = 3) +
  geom_smooth(method = "lm", se = FALSE) +
  gghighlight(iso3c == my_iso_code) +
  theme_classic(7) +
  labs(
    x = "First Year of Native Representation",
    y = "Polity IV Score, 1992",
    title = "Political Inclusion and Political Liberalization"
  )
```

As in the previous problem set, you can save this plot as an image or PDF using the `ggsave` function.

```{r, eval=FALSE}
ggsave('figure-07-1.png')
```

In R Studio, you can also save the plot by clicking the "Export" button at the top of the plots window. 

What does this plot tell you about the general relationship between political inclusion and political liberalization? Is your country above or below the trend line?

***


# 3. Medical Infrastructure and Human Development

As we noted earlier, the data set contains multiple independence years for countries that were administered by more than one colonial power (i.e. Cameroon). In order to make the rest of the plots in this exercise, we use `dplyr` to remove the duplicate rows.

```{r}
africa_df <- africa_df %>%
  select(-c(country.2, native.rep.yr)) %>%
  unique()
```

Now we can plot the relationship between medical infrastructure (measured by physicians per 1,000 people in 1960) and human development after independence (measured by the average life expectancy at birth in 1992).

```{r message=FALSE, warning=FALSE}
ggplot(africa_df, aes(x = physicians, y = lifexp.92, label = iso3c)) +
  geom_text(size = 3) +
  geom_smooth(method = "lm", se = FALSE) +
  gghighlight(iso3c == my_iso_code) +
  theme_classic(7) +
  labs(
    x = "Physicians per 1,000 People, 1960",
    y = "Life Expectancy at Birth, 1992",
    title = "Medical Infrastructure and Life Expectancy"
  )
```

You can save this plot using the `ggsave` function.

```{r, eval=FALSE}
ggsave('figure-07-2.png')
```

In R Studio, you can also save this plot by clicking the "Export" button at the top of the plots window.

How might you explain the apparent relationship between the medical infrastructure in 1960 and life expectancy in 1992?

***


# 4. Human Capital and Human Development

Finally, we can examine the relationship between higher education and human development. The data on attainment of tertiary education is produced using Barro-Lee Educational Attainment Dataset. For the purposes of this exercise, we'll use the percent of 20 to 29-year-olds who have completed some form of tertiary education, averaged from 1960 to 1965. Note that data is not available for every Sub-Saharan country, so your country may not be represented in the plot.

```{r message=FALSE, warning=FALSE}
ggplot(africa_df, aes(x = tertiary.ed/100, y = lifexp.92, label = iso3c)) +
  geom_text(size = 3) +
  geom_smooth(method = "lm", se = FALSE) +
  gghighlight(iso3c == my_iso_code) +
  theme_classic(7) +
  scale_x_continuous(labels = scales::percent) +
  labs(
    x = "Attainment of Tertiary Education\n(20 to 29-year-olds, 1960 to 1965)",
    y = "Life Expectancy at Birth, 1992",
    title = "Higher Education and Human Development"
  )
```

You can save this plot using the `ggsave` function.

```{r, eval=FALSE}
ggsave('figure-07-3.png')
```

In R Studio, you can also save this plot by clicking the "Export" button at the top of the plots window.

What does this plot suggest about the relationship between colonial education and human development? 



