---
title: "Homework 6"
author: "Your Name Here"
institute: "Old Dominion University"
format: 
  html:
    theme: lux # Check here for more themes: https://quarto.org/docs/output-formats/html-themes.html
    code-tools: true
    code-fold: true
    code-summary: "Code"
    code-copy: hover
    link-external-newwindow: true
    tbl-cap-location: top
    fig-cap-location: bottom

self-contained: true
editor: source
---

```{r setup, include=FALSE}
# DO NOT EDIT THIS

knitr::opts_chunk$set(fig.align = 'center')
knitr::opts_chunk$set(out.width = '90%')
knitr::opts_chunk$set(results = 'hold')
knitr::opts_chunk$set(fig.show = 'hold')
knitr::opts_chunk$set(error = TRUE)
knitr::opts_chunk$set(warning = FALSE)
knitr::opts_chunk$set(message = FALSE)
par(mar = c(4.1, 4.1, 1.1, 4.1))

hooks = knitr::knit_hooks$get()
hook_foldable = function(type) {
  force(type)
  function(x, options) {
    res = hooks[[type]](x, options)
    
    if (isFALSE(options[[paste0("fold.", type)]])) return(res)
    
    paste0(
      "<details open><summary>", gsub("^p", "P", gsub("^o", "O", type)), "</summary>\n\n",
      res,
      "\n\n</details>"
    )
  }
}

knitr::knit_hooks$set(
  output = hook_foldable("output"),
  plot = hook_foldable("plot")
)

Q <- 0
```

One of the most famous economics papers in Gary Becker's [*Crime and Punishment*](https://www.nber.org/system/files/chapters/c3625/c3625.pdf).  In this paper, Becker theorizes that criminal behavior is "rational" when the benefits of crime outweigh the economic costs of crime.  In math:

$$E[\text{Crime}] = P(\text{Sanction})\times\text{Sanction} + [1-P(\text{Sanction})]\times\text{Rewards}$$

where $\text{Sanction}$ represents the fines, jail time, or lost opportunities incurred by the criminal (a negative value) if caught, $P(\text{Sanction})$ is the probability of getting caught, and $\text{Rewards}$ are the benefits of getting away with the criminal act (a positive value).  In Becker's model, these three factors jointly determine the expected value of crime.  This can also be thought of as an opportunity cost story. All else equal, in this model, crime is more costly to those earning high wages compared to those earning low wages since there's more to lose.

Flückiger \& Ludwig ([2015](https://doi.org/10.1016/j.jdeveco.2014.12.003)) investigate Becker's model of crime by thinking about piracy and fishing.

Commercial fishing requires boats, and boats can be used to fish or for other purposes, such as piracy.  The only barrier to entry into both markets is owning one of these boats.  Flückiger \& Ludwig then ask the question: do worse fishing conditions lead boat owners to turn to piracy?^[As a note, fisheries represent a classic economic common pool resource that can be plagued by overuse (economists call this the "tragedy of the commons").  Because of this, various extra-governmental agencies monitor commercial fishing activity, generating good data on commercial fish production by country. International trade depends heavily on oceanic transport, and piracy represents an important threat to the free flow of goods across countries, leading to systematic data collection on acts of piracy.]

The data used in this paper can be found [here](https://alexcardazzi.github.io/econ400/data/pirates.csv).  It is recommended that you read the paper, which can be found on Canvas, before completing this homework.

## Question `r Q <- Q+1; Q`

```{r include=FALSE}
q <- 0
```

The authors in this paper use an instrumental variable approach to estimate the causal effect of fishing conditions on piracy.

`r q <- q+1; letters[q]`. Why can't the authors use a different causal inference technique we've learned? (**2 Points**)

*Write your response here.*

`r q <- q+1; letters[q]`. Describe the identification strategy used in this paper. (**1 Points**)

*Write your response here.*

`r q <- q+1; letters[q]`. Draw a DAG for this setting or write down the first and second stage regressions used in the IV estimation. (**2 Points**)

```{r}
# Write your code here.
```



## Question `r Q <- Q+1; Q`

```{r include=FALSE}
q <- 0
```

The data for this homework can be found [here](https://alexcardazzi.github.io/econ400/data/pirates.csv).  Use this data to complete this homework.

`r q <- q+1; letters[q]`. Read the data into R.  Save the data as an object called `pirates`. (**1 Points**)

```{r}
# Write your code here.
```

`r q <- q+1; letters[q]`. Generate a summary statistics table using `modelsummary()`. (**1 Points**)

```{r}
# Write your code here.
```



## Question `r Q <- Q+1; Q`

```{r include=FALSE}
q <- 0
```

Create some data visualizations:

`r q <- q+1; letters[q]`. Use the following code to generate a map of the world.  After, add the latitude and longitude points in `pirates` onto the map.  The colors of the points should correspond to the continent they are assigned in `pirates`. (**1 Points**)

```{r, warning=FALSE, message=FALSE}
# Write your code here.
```

`r q <- q+1; letters[q]`. Recreate Figure 4 from the paper.  Maintain the same coloring scheme as the previous plot. (**1 Points**)

```{r}
# Write your code here.
```



## Question `r Q <- Q+1; Q`

```{r include=FALSE}
q <- 0
```

Take a look at Table 2 from Flückiger \& Ludwig.  Use `pirates` to answer the following parts.

`r q <- q+1; letters[q]`. Replicate the parameter estimates from Columns 2-3 and 6-7 from Table 2.^[You'll notice that some of the regressions require continent-specific-trends.  This is another word for varying slopes.  See [this information](https://lrberge.github.io/fixest/articles/fixest_walkthrough.html#varying-slopes-fex) for help.  In addition, be sure to cluster your standard errors.] (**3 Points**)

```{r, warning=FALSE, message=FALSE}
# Write your code here.
```

`r q <- q+1; letters[q]`. Display the coefficients in a table generated via `modelsummary`. (**2 Points**)

```{r}
# Write your code here.
```


`r q <- q+1; letters[q]`. What is the general interpretation of these results? (**2 Points**)

*Write your response here.*


## Question `r Q <- Q+1; Q`

```{r include=FALSE}
q <- 0
```

Take a look at Table 3 from Flückiger \& Ludwig.  Use `pirates` to answer the following parts.

`r q <- q+1; letters[q]`. Replicate Columns 1 and 2 from Table 3.^[Note: check out [this vignette](https://lrberge.github.io/fixest/articles/fixest_walkthrough.html#instrumental-variables) for information about how to estimate instrumental variables via 2SLS with `fixest`.] (**3 Points**)

```{r}
# Write your code here.
```


`r q <- q+1; letters[q]`. Display these coefficients in a table generated via `modelsummary`.  Order the regressions as Column 1's replication, the first of Column 2, and then Column 2's replication. (**2 Points**)

```{r}
# Write your code here.
```

`r q <- q+1; letters[q]`. Use `fitstat()` to display the F-statistic and the Wald-statistic.  What are the general takeaways from these tests? (**1 Points**)

```{r}
# Write your code here.
```

*Write your response here.*

`r q <- q+1; letters[q]`. What is the general interpretation of the results? How are they different from the OLS results, if at all? (**2 Points**)

*Write your response here.*

`r q <- q+1; letters[q]`. Do you think it was important that the authors used an IV instead of OLS? Why or why not? (**1 Points**)

*Write your response here.*



## Question `r Q <- Q+1; Q`

```{r include=FALSE}
q <- 0
```


Discuss the IV assumptions.

`r q <- q+1; letters[q]`. Does the IV satisfy the necessary assumptions? (**2 Points**)

*Write your response here.*

`r q <- q+1; letters[q]`. Do you think the estimates identify a plausibly causal relationship?  (**2 Points**)

*Write your response here.*

`r q <- q+1; letters[q]`. What do you think about the external validity of these results? In other words, are the results of this paper extendable to more generalizable settings? (**2 Points**)

*Write your response here.*

