---
title: "Problem set 3: Relationships"
output: html_document
---


# Instructions


- You will do your work in this `Quarto` 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(socviz)
library(juanr)
```



# Task 1: Money in politics


We're going to work with the Database on Ideology, Money in Politics, and Elections (`bonica`), which has candidate-level information on campaign fundraising. 


```{r}
bonica
?bonica
```


How much money did the average candidate from each party raise in the 2016 election cycle? Calculate the average amount of money raised (`total_receipts`) per political party in the 2016 cycle. 


```{r}

```


**Q1: How much money did the TOP fundraising party raise?**



Look only at California politicians. Among these, who SPENT the most of their OWN money (`contribs_from_candidate`) across any election cycle? Hint: this is a rare case where you will need to use two filters *sequentially* instead of one.


```{r}


```


**Q2: Who spent the most of their own money?**




How much do the number of donors vary *within* states? For the 2018 cycle, calculate the standard deviation of the number of donors each candidate received money from (`num_distinct_donors`), broken down by state. 

Then, look at which state has the HIGHEST standard deviation of the number of distinct donors. Hint: if you store the output as an object, you can preview the data and "sort" it to find the state with the lowest standard deviation. 


```{r}

```


**Q3: Which state has the HIGHEST standard deviation of distinct donors?**


The reason this state has such a high standard deviation of the number of unique donors is because of one candidate who is unusually good at fundraising. Dig around in the data for this state; who is this person?

```{r}



```


**Q4: Who is this person?**



**Q5: What can we infer from the fact that this state has the highest standard deviation of the number of unique donors?**





# Task 2: Leaders


Look at the leader dataset on world leaders:


```{r}
leader
?leader
```


In 2005, how many years of experience did the median leader have?


```{r}

```


**Q6: how many years of experience does the median leader have?**



What percent of world leaders in 1991 had experience in a rebellion?

```{r}


```


**Q7: What percent of world leaders in 1991 had experience in a rebellion?**



How is the age of world leaders changing over time? Calculate the average age of world leaders per year. Plot the average ages as a lined time series.


```{r}


```


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



## Task 3: bots


Look at the bot data on how Americans feel about different political issues:

```{r}
bot
?bot
```


What percent of of WHITE respondents in `bot` support concealed carry?


```{r}


```


**Q9: What percent of of WHITE respondents in `bot` support concealed carry?**



Let's look at how the different religious groups feel about abortion (`prochoice`). Calculate the percent of respondents who support or oppose `prochoice`, broken down by religion. BUT: let's only look at Mormons, Protestants, and Catholics. 


```{r}


```


**Q10: Among these three, what religious group has the highest SUPPORT to `prochoice` as a PERCENT OF THE GROUP?**
