**Open Review**. We want your feedback to make the book better for you and other students. You may annotate some text by selecting it with the cursor and then click the on the pop-up menu. You can also see the annotations of others: click the in the upper right hand corner of the page

## 10.7 Exercises

For the course of this section, you will work with `Guns`, a balanced panel containing observations on criminal and demographic variables for all US states and the years 1977-1999. The dataset comes with the package `AER` which is already installed for the interactive R exercises below.

#### 1. The Guns Dataset

**Instructions:**

Load both the

`AER`package and the`Guns`dataset.Get yourself an overview over the dataset using the

`summary()`function. Use`?Guns`for detailed information on the variables.Verify that

`Guns`is a balanced panel: extract the number of years and states from the dataset and assign them to the predefined variables`years`and`states`, respectively. Afterwards use these variables for a logical comparison: check that the panel is balanced.

**Hints:**

- Use
`library()`and`data()`to attach the package and load the dataset, respectively. - Use
`summary()`to obtain a comprehensive overview of the dataset. - Remember that in a balanced panel the number of entities times the number of years equals the total number of observations in the dataset. The basic functions
`levels()`,`length()`and`nrow()`may be useful.

#### 2. Strict or Loose? Gun Laws and the Effect on Crime I

There is a controversial debate whether and if to what extent the right to carry a gun influences crime. Proponents of so-called “Carrying a Concealed Weapon” (CCW) laws argue that the deterrent effect of guns prevents crime, whereas opponents argue that the public availability of guns increases their usage and thus makes it easier to commit crimes. In the following exercises you will empirically investigate this topic.
To begin with consider the following estimated model
\[\widehat{{\log(violent_i)}} = 6.135 - 0.443 \times law_i,\]
with \(i=1,\ldots,51\) where `violent` is the violent crime rate (incidents per 100000 residents) and `law` is a binary variable indicating the implementation of a CCW law (1 = yes, 0 = no), respectively.

The estimated model is available as `model` in your working environment. The packages `AER` and `plm` have been loaded.

**Instructions:**

- Extend and estimate the model by including state fixed effects using the function
`plm()`and assign the model object to the predefined variable`model_se`. Can you think of an unobserved variable that is captured by this model specification? - Print a summary of the model which reports cluster robust standard errors.
- Test whether the fixed state effects are jointly significant from zero. To do so use the function
`pFtest()`. Use`?pFtest`for additional information.

**Hints:**

The function

`plm()`allows you to conduct regressions with panel data and works very similar to`lm()`. You have to specify the entity and time indicators inside as a vector using the argument`index`and specify the estimator to be used with the argument`model`(for the fixed effects estimator this is`“within”`).As usual you can use

`coeftest()`in conjunction with appropriate arguments to obtain a summary output with robust standard errors.`pFtest()`expects two model objects. The first model includes fixed effects, the second does not.

#### 3. Strict or Loose? Gun Laws and the Effect on Crime II

As touched upon at the end of the last exercise it is reasonable to also include time effects which is why we now consider the model
\[\begin{align}\log(violent_i) & = \beta_1\times law_i + \alpha_i + \lambda_t + u_i,\end{align}\]
for \(i=1,\ldots,51\) and \(t=1977,\ldots,1999\).
The models `model` and `model_se` from the previous exercises are available in your working environment. The packages `AER` and `plm` have been attached.

**Instructions:**

- Estimate the model above and assign it to the variable
`model_sete`using`plm()`. - Print a summary of the model which reports robust standard errors.
- Test whether both state and time fixed effects are jointly significant.

**Hints:**

- To additionally incorparate time fixed effects, one can set the argument
`effect=“twoways”`inside of`plm()`. - Note that we want to test whether the state
*and*time fixed effects are jointly significant.

#### 4. Strict or Loose? Gun Laws and the Effect on Crime III

Despite the evidence for state as well as time effects found in exercise 3, there still might be a bias due to omitted variables such as sociodemographic characteristics. The following model accounts for the latter:
\[\begin{align}\log(violent_i) & = \beta_1\times law_i + \beta_2\times density_i + \beta_3\times income_i + \beta_4\times population_i \\&\quad + \beta_5\times afam_i + \beta_6\times cauc_i + \beta_7\times male_i + \alpha_i + \lambda_t + u_i.\end{align}\]
See `?Guns` for detailed information on the additional variables.

The packages `AER` and `plm` have been loaded.

**Instructions:**

- Estimate the extended model and assign it to the predefined variable
`model_sete_ext`. - Print a robust summary of the estimated model. What can you say about the effect of a CCW law?

#### 5. Fixed Effects Regression - Two Time Periods

Recall the fixed effects model from Exercise 10.2, but now assume that you only have observations for the years 1978 and 1984. Consider the two model specifications
\[\begin{align}
\log(violent_{i1984}) - \log(violent_{i1978}) = \beta_{BA}\times(law_{i1984}-law_{i1978}) + (u_{i1984} - u_{i1978})
\end{align}\]
and
\[\begin{align}
\log(violent_{it}) = \beta_{FE}\times law_{it} + \alpha_i + u_{it},\\
\end{align}\]
with \(i=1,\ldots,51\) and \(t=1978,1984\).
In this exercise you need to show that \(\widehat{\beta}_{BA}=\widehat{\beta}_{FE}\).
The subsets of `Guns` for the years 1978 and 1984 are already available as `Guns78` and `Guns84` in your working environment. The packages `AER` and `plm` have been loaded.

**Instructions:**

- Compute the differences necessary to estimate the first model and assign them to the variables
`diff_logv`and`diff_law`. - Estimate both models. Use the differenced data to estimate the first model and
`plm()`for the second. - Verify with a logical comparison that both procedures numerically yield the same estimate. Use the variables
`coef_diff`and`coef_plm`which contain the relevant coefficients rounded to the fourth decimal place.

**Hints:**

- Keep in mind that the dependend variable is log-transformed.
- You may use
`plm()`as in the previous exercises. Note that you only need a subset of the original`Guns`dataset. Theargument`subset`allows to subset the dataset passed to the argument`data`. Alternatively, you can join the two datasets`Guns78`and`Guns84`using, e.g.,`rbind()`. - Use the logical operator
`==`to compare both estimates.