---
title: "Homework 5"
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
```



Synthetic Control represents a powerful tool for the evaluation of economic policies.  In The Mixtape, Scott Cunningham writes:

> The estimator has been so influential that Athey and Imbens (2017a) said it was "arguably the most important innovation in the policy evaluation literature in the last 15 years" (p.3).

This homework is based on a paper "Voting after the Bombings: A Natural Experiment on the Effect of Terrorist Attacks on Democratic Elections" by José Montalvo published in *The Review of Economics and Statistics* ([link](https://www.jstor.org/stable/41349103)) that analyzes the impact of a terrorist attack in Madrid, Spain in 2004 on voting outcomes. The key issue in this analysis, like all causal inference examples covered in class, revolves around the comparison of the actual outcomes in Spain after the attack to the unobservable conterfactual potential outcome that would have occurred in Spain in the absence of the attack. In this homework, you will replicate the results of Montalvo (2011).

Before beginning, be sure to carefully read through the paper.

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

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

`r q <- q+1; letters[q]`. Summarize the main research question and how the author approached answering it. In your answer, be sure to identify the outcome variable(s).  (**1 Point**)

*Your answer here.*


`r q <- q+1; letters[q]`. Provide a discussion about how, if at all, the author addresses backdoors, colliders, etc. (**Bonus: 1 Point**)

*Your answer here.*


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

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

For the following questions, use the following [data](https://alexcardazzi.github.io/econ708/data/dataVAB_1.csv).

`r q <- q+1; letters[q]`. Read the data into an object called `vab`. Below you will find a list of the dataset's variables copy-and-pasted from the author's replication package. (**0 Points**)

- id: number corresponding to each province (id=53 is the aggregate at the national level)
- pp: proportion of vote for the conservative party
- psoe: proportion of vote for the socialist party
- year
- dtreat=1 for treated group
- voters: potential voters (electoral census)
- part: participation rate

```{r}
# Your code here.
```

`r q <- q+1; letters[q]`. Describe the structure of the data (e.g. the unit of observation, treatment and control groups, etc.). Is this what the "ideal" dataset would look like to answer the research question? (**2 Points**)

*Your answer here.*


`r q <- q+1; letters[q]`. Construct the author's main outcome variable, and then use `modelsummary` to generate summary statistics for the provinces. (**1 Point**)

```{r}
# Your code here.
```

`r q <- q+1; letters[q]`. Plot time series that shows the value of the outcome variable over time for the treated and control group. This should be a replication of Figure 2 from the paper. (**1 Point**)

```{r}
# Your code here.
```

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

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

For this question, turn to the difference-in-differences analysis in Part III of the paper.

`r q <- q+1; letters[q]`. What are the assumptions the author is making (explicitly and implicitly) in estimating the DiD, and how are they addressing them? (**1 Point**)

*Your answer here.*


`r q <- q+1; letters[q]`. Estimate Equation 1 in the paper. The numbers you get should be very close, but perhaps not exact.^[Do not worry about tabulating the results -- just print the `summary()`.] (**1 Point**)

```{r}
# Your code here.
```

`r q <- q+1; letters[q]`. Estimate and plot an event study version of the above estimates. Use heteroskedasticity robust standard errors. (**1 Point**)

```{r}
# Your code here.
```

`r q <- q+1; letters[q]`. Interpret the results of the DiD and the event study, and provide a short discussion of the strengths and weaknesses of this section of the paper. (**1 Point**)

*Your answer here.*


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

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

For this question, turn to the synthetic control analysis in Part IV of the paper.

`r q <- q+1; letters[q]`. Prepare the data and estimate the synthetic control.^[For a hint, create/add a character version of the ID variable to the datatset, use the entire pre-period for both `time.predictors.prior` and `time.optimize.ssr`, and do not use `special.predictors`. Use the outcome, `pp`, and `psoe` as the predictors.] (**1 Point**)

```{r sc, cache = TRUE}
# Your code here.
```

`r q <- q+1; letters[q]`. Create a table that compares the "real" treated unit, to the synthetic and an equally weighted mean of the units in the donor pool. (**1 Point**)

```{r}
# Your code here.
```

`r q <- q+1; letters[q]`. Create a table showing the units in the donor pool that were given the most weight. Provide some thoughts on this table. (**1 Point**)

```{r}
# Your code here.
```

*Your answer here.*


`r q <- q+1; letters[q]`. Plot the outcomes for the synthetic and the real unit. Be sure to include relevant information (e.g. a vertical line showing treatment, a legend, labels for axes, etc.). (**1 Point**)

```{r}
# Your code here.
```

`r q <- q+1; letters[q]`. What makes this application different from the one about West Germany in the notes, and what do you think of this pivot? (**2 Points**)

*Your answer here.*


`r q <- q+1; letters[q]`. Run (and plot) a placebo tests for the synthetic displayed above. (**1 Point**)

```{r placeboz, cache = TRUE}
# Your code here.
```

`r q <- q+1; letters[q]`. Estimate a p-value for each time period.^[Do not worry about trimming out poorly fitting placebos, though this is something you would want to address in theory.] Interpret the output. (**1 Point**)

```{r}
# Your code here.
```

*Your answer here.*


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

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

`r q <- q+1; letters[q]`. Place both the event study and synthetic control on the same set of axes, and compare them in words. (**1 Point**)

```{r}
# Your code here.
```

*Your answer here.*


`r q <- q+1; letters[q]`. Which analysis do you prefer, and why?^[If you do not care for either (or think they're both good), that is okay, just explain why.] Be sure to consider the assumptions required, the statistical precision, effect magnitude, etc. (**2 Points**)

*Your answer here.*




