---
title: "ps-causality"
output: html_document
date: "2023-11-08"
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```


# Instructions


- You will do your work in this `Rmarkdown` document but will submit all your answers on Canvas
- *very important*: As you move through the document, make sure to run all code chunks (grey bits) that already have code in them
- Write your own code in the empty code chunks
- Useful shortcuts: 
    - to run all the code in a specific code chunk, press the green right-facing triangle at the top right of the code chunk
    - to run all *prior* code chunks, press the downward-facing gray triangle at the top right of the code chunk



```{r load-libraries, warning=FALSE, message=FALSE}
library(tidyverse)
library(broom)
set.seed(1990)
```



# Task 1: Experiments and counterfactuals


Imagine the following scenario:


> You're a researcher that wants to test whether rebel groups that have strong ideological convictions abuse civilians less or more than rebel groups with weak ideological convictions. You also know that, in civil wars where the state is run by a military dictatorship, civilians are more likely to be abused in general, although the state being a military dictatorship has no effect on the rebel group's ideology. 


**Q1: Will the fact that civilians are abused more in civil wars where the state is run by a dictatorship bias your study?**



Imagine the following scenario:

> a researcher wants to know to what extent, if at all, a six-week aborition ban (e.g., https://shorturl.at/fiO03) would cause a reduction in abortions. They look at all the states that passed abortion bans, collect data on abortions before and after the ban, and test whether there is a meaningful decrease in abortions after the law passes. Let's say Florida passed a six-week ban, but Washington state did not. 



**Q2: what is the "potential outcomes" counterfactual for the abortion rates observed in Florida (which passed a six week ban)? Remember, This is the counterfactual that is hypothetical, and cannot be observed.**



**Q3: what is the "control" condition or _observable_ counterfactual for Florida in this study?**




# Task 2: Simulating data


Simulate data that shows corruption hurts a country's economic development, with the following characteristics:

- You have n = 200 countries
- Each country has a corruption level of 50, plus or minus 10 (0 = no corruption, 100 = high corruption)
- Each country has a GDP per capita of about 50,000, plus or minus 8,000
- corruption causes a decrease in GDP per capita of 1,000 per unit of corruption


```{r}
set.seed(1990)


```


Fit a model that estimates the effect of corruption on GDP per capita:


```{r}


```



**Q4: What is the estimated coefficient for the intercept in this model?**



Simulate data that shows that: terrorist attacks increase the public's sense of anxiety; and that this increase in anxiety, leads to higher support for more extreme political candidates. Here are the characteristics:


- it's a country that has N = 800 cities
- there's a lot of terrorist attacks happening. the cities experience, on average, 8 terrorist attacks, plus or minus 1 attack
- people in this country are anxious. On a 100-point "anxiety scale", the average city is at 20, +/- 2. 
- terrorism causes *increases* in anxiety: for every terrorist attack, anxiety increases by 2 points.
- Extreme political candidates are not so popular. The average vote share of an extreme political candidate is roughly 15, +/- 3. 
- as cities get more anxious, support for these candidates *increases*. Say that for every point of anxiety, support for extreme candidates goes up by 0.5 points. 


```{r}
set.seed(1990)


```



Now, make a scatterplot of the relationship between the number of terror attacks a city has and the level of support for extreme candidates in that city. Color the points by `anxiety` level. Include an OLS line.


```{r}

```


**Q5: right click the graph --> "save image as" --> and save it somewhere on your computer. You will need to submit the plot!**


Now, using a model, what is the effect of terrorism on support for extreme political candidates?


```{r}


```



**Q6: what is the estimated effect of terrorism on support for extreme candidates?**



**Q7: would it be a good idea, in this case, to control for anxiety? Why or why not?**



Simulate data that shows that the relationship between education and ideology is confounded by class. Here are the characteristics:

- You have n = 500 people
- Most people have 18 years of education, plus or minus 2 (education)
- People are either high income, or low income, equally likely to be one or the other (class)
- Most people are perfectly centrist on a (0-100 ideological scale, 0 = conservative, 100 liberal), plus or minus 5 (ideology)
- Every additional year of education makes someone more liberal, by about 1 point
- People who are high income get, on average, about 5 years more of education
- People who are high income are, on average, about 10 points more liberal



```{r}
set.seed(1990)


```



Fit a model that estimates the effect of education on ideology. 


```{r}

```


**Q8: about how much larger is your estimated effect than the true effect? To answer, calculate = (estimated effect / true effect) X 100**



## Task 3: DAGs and confounds


Go to [dagitty.net](https://www.dagitty.net/dags.html) and click on "Model --> new model". Make a DAG where you look at whether foreign aid reduces a country's level of corruption. Incorporate at least 5 other variables in your DAG. 



**Q9: right click the graph --> "save image as" --> and save it somewhere on your computer. You will need to submit the plot!**


**Q10: In 3-4 sentences, explain why you chose the variables you chose and how you decided what effects each one might have (and not have)**.


