---
title: "Problem set 7: Uncertainty"
output: html_document
---


# 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(juanr)
library(moderndive)
```





## Task 1: The draft


Imagine the following: In the 1960s all men of military age (18+ years) became draft eligible to fight in the Vietnam War. A lottery is used where the social security numbers of draft eligible men were randomly drawn. Those chosen would have to serve in the military. 


**Q1: for which of the following could the random lottery draft be used as a natural experiment?**

 - To study the effects of military service on long-term mental health
 - To study why people choose to join the military
 - To study whether drafts are effective tools of recruitment or ultimately counterproductive
 

Now imagine that, contrary to official policy, people could pay unscrupulous doctors to produce reports of illnesses and disabilities that would *disqualify* them from the draft. 


**Q2: In which of the following ways would this mess up the natural experiment? Choose one** 


- ability to pay a doctor to falsify report becomes a fork
- ability to pay a doctor to falsify report becomes a pipe
- ability to pay a doctor to falsify report becomes a collider



Say your data for the draft study looked like this:


```{r}
df = read_rds("https://www.dropbox.com/scl/fi/hxx1i769gvzyogwdj64pb/draft-study.rds?rlkey=uz6g2ffz70c02hmtmwhlo4no8&dl=1")
df
```


Look at whether the people who were and weren't drafted are *balanced* on background characteristics (high school completion (0/1), criminal conviction (0/1), high school GPA, and marital status (0/1)):


```{r}


```


On which characteristic are draftees the most unbalanced? 


**Q3: On which characteristic are draftees the most unbalanced?**



## Task 3: Feelings


Look at the feeling thermometer data. Just like in class, we'll pretend this data is the whole of the United States.


```{r}
therm
?therm
```


What is the average feeling thermometer for the police in the whole dataset (`therm`)? Calculate the average below: 


```{r}

```


**Q4: what is the average level of support for the police?**



Now, let's look at how much our estimates might vary across samples. Take 1,000 samples each of size 30 and calculate the average support for police in each. Note: leave set.seed(1990) where it is!

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


```


**Q5: what is the lowest average level of support for the police that you estimated in your samples?**



Now, bias the samples in a form of your choosing so that the sample estimates do not converge on the population parameter. Plot the resulting distribution. 


```{r}


```


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



### Bootstrapping


Now, let's go back to treating `therm` as what it is: a sample. How much uncertainty should we have in our estimate of average police support in this sample? Generate 1,000 bootstrapped samples of the dataset. Between what two values do 95% of observations fall?



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

```


**Q7: Between what two values do 95% of averages fall?**



Repeat the same procedure above, except this time only for respondents who identify as "Middle Eastern".

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

```


**Q8: Between what two numbers do 95% of averages fall?**



**Q9: Why is the range of values in Q7 different than in Q8?**



Look at the output from the following regression:


```{r}
lm(ft_police ~ sex, data = therm) %>% broom::tidy()
```


**q10 Roughly speaking, what does the value in `std.error` for `sexFemale` tell us?**







