# 7 Regression (Panel Data)

## 7.1 Overview

In this seminar and homework, we will cover fixed-effect models for panel data.

## 7.2 Seminar

Up until now, almost all the data we have worked with on this course has been *cross-sectional*, which means that we have been working with one observation for each unit in our data. Whenever we have more than one observation in our data per unit, we can describe this data as having a *panel* structure. For instance, if we have data on US states (our units), and we observe the relevant covariate and outcome variables for each state at multiple points in time, this would constitute panel data.

Panel data is normally written with a double subscript where, for instance, \(Y_{it}\) would be an observation of our outcome variable for unit \(i\) at time \(t\).

If our goal is to try and estimate causal relationships using observational data, panel data is useful because we can make use of the fact that we observe variation in our main explanatory variables *within units over time* to rule out some forms of omitted variable bias.

**More Guns, Less Crime**

In his book More Guns, Less Crime, gun rights advocate John Lott argues that crime rates in the United States decrease when gun ownership restrictions are relaxed. The data used in Lott’s research compares violent crimes, robberies, and murders across 50 states to determine whether so called “shall issue” laws decrease crime rates. These laws are generally seen as permissive, as a person applying for a licence to carry a concealed weapon doesn’t have to provide justification or “good cause” for requiring a concealed weapon permit. So far 41 states have passed “shall issue” laws.

Lott argues that “shall issue” laws decrease violent crime because criminals are deterred by the risk of attacking an armed victim. We will use the dataset provided by Lott to test whether there is evidence to support his claims.^{1} Download the data file, `guns.csv`

, from the link above, and store it in your `data`

folder as you have done in previous weeks. Then load the data into R:

The variables in the data are described below.

Variable | Description |
---|---|

`mur` |
Murder rate (incidents per 100,000) |

`rob` |
Robbery rate (incidents per 100,000) |

`vio` |
Violent crime rate (incidents per 100,000) |

`shall` |
1 if the state has a shall-carry law in effect in that year, 0 otherwise |

`incarc_rate` |
Incarceration rate in the state in the previous year (sentenced prisoners per 100,000 residents; value for the previous year) |

`pm1029` |
Percent of state population that is male and aged between 10 and 29 |

`pw1060` |
Percent of state population that is white and aged between 10 and 60 |

`pb1060` |
Percent of state population that is black and aged between 10 and 60 |

`avginc` |
Average state income (in thousands of dollars in 1983) |

`density` |
Population per square mile, in thousands |

`pop` |
State population, in millions |

`year` |
Year (1977-1999) |

`stateid` |
State identifier |

Note that this data has a panel structure of the sort described above. Our unit of analysis here is a state in the US, and we observe each state 23 times, once for each year in the data.

**Question 1**

Create two boxplots which depict the variation in our outcome variable, `mur`

, as a function of `stateid`

and `year`

. Be sure to use informative axis labels. Interpret the resulting graphs. If you are struggling, look back at the code that we used last week to create boxplots.

## Reveal answer

```
boxplot(mur ~ stateid,
data = guns,
xlab = "State",
ylab = "Murder rate",
cex.axis = .3) # This argument makes the axis labels smaller
```

```
boxplot(mur ~ year,
data = guns,
xlab = "Year",
ylab = "Murder rate",
las = 2) # This argument rotates the axis labels
```

The plots show two sources of variation in our data: variation by state and variation over time. If we were only to observe one year of data, then the only variation in our outcome would be from differences across states. However, because our data here has a panel structure, we also have variation in the murder rate over time.

**Question 2**

Estimate a linear regression with `mur`

as the dependent variable and `shall`

as the only explanatory variable. What does the regression tell you about the theory that more permissive gun laws decrease crime?

## Reveal answer

```
##
## Call:
## lm(formula = mur ~ shall, data = guns)
##
## Residuals:
## Min 1Q Median 3Q Max
## -6.6434 -3.1434 -0.4136 2.6465 15.0161
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 7.3434 0.1241 59.191 < 2e-16 ***
## shall -2.0595 0.2492 -8.264 3.85e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 3.649 on 1148 degrees of freedom
## Multiple R-squared: 0.05615, Adjusted R-squared: 0.05533
## F-statistic: 68.29 on 1 and 1148 DF, p-value: 3.849e-16
```

States where “shall issue” laws are in place have, on average, 2.06 fewer murders per 100,000 inhabitants than states without such laws.

Although this difference is consistent with the theory suggested by Lott – that is, the murder rate is indeed somewhat lower in states where “shall issue” laws are in operation – the coefficient in this regression does not represent a causal quantity as there may be many reasons why states with a “shall issue” law are different from those without such laws. This is therefore another case where omitted variable bias could be a serious concern.

**Question 3**

Estimate a new regression model which controls for `pop`

, `avginc`

, and `pm1029`

. Present the results of this model and your first model in a table using `screenreg`

from the `texreg`

package. (Hint: you will need to load the `texreg`

package first) Interpret the results.

## Reveal answer

```
library(texreg)
multiple_ols_model <- lm(mur ~ shall + pm1029 + avginc + pop, data = guns)
screenreg(list(simple_ols_model,multiple_ols_model))
```

```
##
## =====================================
## Model 1 Model 2
## -------------------------------------
## (Intercept) 7.34 *** 5.34 ***
## (0.12) (1.60)
## shall -2.06 *** -1.29 ***
## (0.25) (0.24)
## pm1029 0.22 **
## (0.07)
## avginc -0.24 ***
## (0.05)
## pop 0.30 ***
## (0.02)
## -------------------------------------
## R^2 0.06 0.23
## Adj. R^2 0.06 0.23
## Num. obs. 1150 1150
## =====================================
## *** p < 0.001; ** p < 0.01; * p < 0.05
```

The key quantity of interest – the effect of “shall issue” laws on the murder rate – decreases in absolute terms between models 1 and 2. When controlling for population size, average state income, and the proportion of young men in the population, “shall issue” states have a murder rate that is 1.29 lower than states without such laws. The change in the coefficient implies that the simple model above is subject to omitted variable bias.

It is also worth noting that the additional variables included in model 2 explain a reasonably large amount of the variation in the overall murder rate. The variables in model 2 explain 23% of the variation in the murder rate, compared to just 6% for the variables in model 1.

**Question 4**

By now you should be sceptical of the idea that simply including a list of control variables in a regression will ensure that you have removed all omitted variable bias. In this case, there may be other omitted variable that we are not controlling for. Take 2 minutes to discuss this with the person next to you. What are the potentially *unobserved* confounders that might be the source of confounding bias?

## Reveal answer

There are many possible factors that might confound the relationship between the presence of a “shall issue” law and the murder rate. For instance, the states that choose to adopt lax gun laws may be different in several ways from the states that choose not to adopt them. For example, states that adopt these laws may have citizens with different attitudes towards gun crime and gun ownership; may have systematically different police force quality; and may have different crime-prevention programmes. The difficulty for researchers is that there is an essentially

endlesslist of potentially confounding but completely unobserved variables in this example.

**Question 5**

*a.*

The fixed-effect model that you will run in the question below is based on the idea that comparisons *within* states over time are likely to be more informative about the causal effect of “shall issue” laws than comparisons *across* states. To build intuition for this model, in this question we will estimate the effects of such laws using the data from individual states that changed their gun control laws at some point during the study period.

To make these comparisons, use the same regression model that you used above (model 2) but apply it to data from the following states, one at a time: PA; ID; NV. You can use the `subset`

argument of the `lm()`

function to use only a subset of data in the regression. `subset`

takes a logical vector as input, so if you only want to use observations whose `stateid`

is “PA”, you can use `subset = guns$stateid=="PA"`

. Present the models in a table.

## Reveal answer

```
pa_model <- lm(mur ~ shall + pm1029 + avginc + pop, data = guns, subset = guns$stateid == "PA")
id_model <- lm(mur ~ shall + pm1029 + avginc + pop, data = guns, subset = guns$stateid == "ID")
nv_model <- lm(mur ~ shall + pm1029 + avginc + pop, data = guns, subset = guns$stateid == "NV")
screenreg(list(multiple_ols_model, pa_model, id_model, nv_model))
```

```
##
## =======================================================
## Model 1 Model 2 Model 3 Model 4
## -------------------------------------------------------
## (Intercept) 5.34 *** -30.96 -12.51 -55.45
## (1.60) (39.28) (6.17) (29.79)
## shall -1.29 *** 0.48 0.27 -0.81
## (0.24) (0.82) (0.66) (2.56)
## pm1029 0.22 ** -0.01 0.84 *** 2.95 *
## (0.07) (0.45) (0.21) (1.21)
## avginc -0.24 *** -0.26 0.66 0.87
## (0.05) (0.38) (0.34) (0.95)
## pop 0.30 *** 3.39 -5.57 6.78
## (0.02) (3.28) (3.75) (8.42)
## -------------------------------------------------------
## R^2 0.23 0.24 0.60 0.59
## Adj. R^2 0.23 0.07 0.51 0.50
## Num. obs. 1150 23 23 23
## =======================================================
## *** p < 0.001; ** p < 0.01; * p < 0.05
```

*b.* Compare these results to those presented in the answers to question 2. What do these results suggest about within and across state comparisons?

## Reveal answer

The key feature to note here is that the effect of the

`shall`

variable is much smaller in magnitude in the state-specific models than it is in the model where we use data from across all states. What does this mean? When only using variation in changes in gun lawswithinthe same state, we find that the effect of those laws on the murder rate is much smaller. In fact, in two of the states we examine – Idaho (ID) and Pennsylvania (PA) – the introduction of a “shall issue” law appears to be associated with an increase rather than a decrease in the murder rate.

Importantly, the intuition here is that we find one effect when comparing across many different states in the pooled analysis, but we find a very different effect when making comparisons based only within states.

**Question 6**

A very common model for panel data is a fixed-effects regression. By using a fixed-effects model, we are able to control for *any* omitted variable that varies across units (states) but is constant within units over time (years).

A simple fixed-effect model is given by:

\[Y_{it} = \alpha_i + \beta_1 X_{1,it} + \epsilon_{it}\]

where \(i\) indicates units, \(t\) indicates time, and \(X_1\) is our treatment variable of interest and the associated coefficient of interest is given by \(\beta_1\). This model differs from those we have seen previously in the course because the intercept term, \(\alpha_i\) has an \(i\) subscript, indicating that we do not have a single intercept in this model, but rather we have one intercept for every unit in our data.

The idea of the fixed-effect model is that it allows us to assess the effect of our treatment of interest – the “shall issue” law – while holding fixed all differences between states that are constant over time. This means that the analysis we run here is very similar in spirit to the analysis in question 5, where we manually subset the data in order to hold state fixed while assessing the relationship between the `shall`

and `mur`

variables.

Although this notation for this model may look a little different from previous weeks, in essence all we are doing here is adding a categorical variable for state to our regression. In practical terms, a fixed-effect model can be estimated by including the relevant variable as a term in our regression model. Here we would like there to be a fixed effect for each state, and so we simply add `stateid`

to the model formula:

*a.* Present a table that include the models you estimated in questions 1 and 2 and also the new `fe_model`

.

## Reveal answer

```
##
## ==================================================
## Model 1 Model 2 Model 3
## --------------------------------------------------
## (Intercept) 7.34 *** 5.34 *** 2.52
## (0.12) (1.60) (1.63)
## shall -2.06 *** -1.29 *** -0.26
## (0.25) (0.24) (0.15)
## pm1029 0.22 ** 0.30 ***
## (0.07) (0.05)
## avginc -0.24 *** 0.12 *
## (0.05) (0.05)
## pop 0.30 *** -0.53 ***
## (0.02) (0.07)
## stateidAL 4.24 ***
## (0.61)
## stateidAR 1.76 **
## (0.60)
## stateidAZ 1.46 **
## (0.55)
## stateidCA 16.37 ***
## (1.91)
## stateidCO -1.73 ***
## (0.49)
## stateidCT -2.83 ***
## (0.45)
## stateidDE -3.96 ***
## (0.45)
## stateidFL 8.36 ***
## (0.93)
## stateidGA 5.73 ***
## (0.64)
## stateidHI -4.28 ***
## (0.44)
## stateidIA -5.31 ***
## (0.54)
## stateidID -4.85 ***
## (0.54)
## stateidIL 6.68 ***
## (0.87)
## stateidIN 1.20
## (0.62)
## stateidKS -2.11 ***
## (0.51)
## stateidKY 0.53
## (0.60)
## stateidLA 8.54 ***
## (0.60)
## stateidMA -2.68 ***
## (0.56)
## stateidMD 3.35 ***
## (0.52)
## stateidME -5.54 ***
## (0.56)
## stateidMI 5.53 ***
## (0.77)
## stateidMN -4.15 ***
## (0.53)
## stateidMO 3.03 ***
## (0.60)
## stateidMS 4.61 ***
## (0.61)
## stateidMT -4.31 ***
## (0.56)
## stateidNC 3.87 ***
## (0.66)
## stateidND -7.30 ***
## (0.52)
## stateidNE -4.80 ***
## (0.51)
## stateidNH -6.07 ***
## (0.48)
## stateidNJ 0.26
## (0.64)
## stateidNM 2.09 ***
## (0.55)
## stateidNV 3.81 ***
## (0.46)
## stateidNY 11.04 ***
## (1.24)
## stateidOH 2.84 **
## (0.86)
## stateidOK 0.95
## (0.56)
## stateidOR -2.58 ***
## (0.54)
## stateidPA 3.45 ***
## (0.91)
## stateidRI -4.82 ***
## (0.49)
## stateidSC 2.69 ***
## (0.58)
## stateidSD -6.37 ***
## (0.54)
## stateidTN 3.43 ***
## (0.61)
## stateidTX 12.02 ***
## (1.21)
## stateidUT -5.18 ***
## (0.52)
## stateidVA 1.83 **
## (0.59)
## stateidVT -5.95 ***
## (0.53)
## stateidWA -1.55 **
## (0.55)
## stateidWI -2.89 ***
## (0.58)
## stateidWV -1.92 **
## (0.61)
## stateidWY -4.37 ***
## (0.47)
## --------------------------------------------------
## R^2 0.06 0.23 0.87
## Adj. R^2 0.06 0.23 0.87
## Num. obs. 1150 1150 1150
## ==================================================
## *** p < 0.001; ** p < 0.01; * p < 0.05
```

*b.* We saw in week 5 of the course that when we include a categorical variable in a regression, the resulting coefficient estimates can be interpreted as the average difference between each category and some baseline category. In this instance, the `stateid`

variable is a categorical variable, and the baseline category is Alaska (AK).

Interpret the coefficients on the `stateidNY`

and `stateidUT`

variables.

## Reveal answer

Holding constant other variables, the murder rate in New York is 11.04 higher than in Alaska.

Holding constant other variables, the murder rate in Utah is 5.18 lower than in Alaska.

*c.* Interpret the coefficient associated with the `shall`

variable.

## Reveal answer

Note that if you would like to suppress the long line of state dummy coefficients from your regression table, you can use the

`omit.coef`

argument in`screenreg()`

as follows:

```
##
## ==================================================
## Model 1 Model 2 Model 3
## --------------------------------------------------
## (Intercept) 7.34 *** 5.34 *** 2.52
## (0.12) (1.60) (1.63)
## shall -2.06 *** -1.29 *** -0.26
## (0.25) (0.24) (0.15)
## pm1029 0.22 ** 0.30 ***
## (0.07) (0.05)
## avginc -0.24 *** 0.12 *
## (0.05) (0.05)
## pop 0.30 *** -0.53 ***
## (0.02) (0.07)
## --------------------------------------------------
## R^2 0.06 0.23 0.87
## Adj. R^2 0.06 0.23 0.87
## Num. obs. 1150 1150 1150
## ==================================================
## *** p < 0.001; ** p < 0.01; * p < 0.05
```

The

`shall`

coefficient in the fixed-effect model implies that, conditional on state, average income, population, and the proportion of young men in the population, “shall issue” laws are associated with a decrease of just 0.26 in the murder rate. This is notably smaller than the coefficients estimated in the two models without state fixed-effects.

It is important to recognise that the fixed-effect model is fundamentally different from the two other models because including state fixed-effects lets us avoid omitted variable bias arising from factors, such as cultural attitudes toward guns, or differences in crime policy, that may vary across states but are constant over time within a state. The useful thing about this strategy is that we are able to hold these factors constant even though they are

unobservedbecause we are basing our estimates on within-state variation in our variables over time.

The regression model with fixed effects gives the most credible estimates for the causal effect of the “shall issue” laws because this model controls for unobserved characteristics that vary between states but that are constant over time.

*d.* What are the remaining threats to causal inference in this example?

## Reveal answer

Although the fixed-effects model above is useful because it rules out confounding for a whole host of omitted factors, there are two remaining sources of bias that we need to worry about.

First, we should still be concerned by any omitted variable bias that comes from variables that vary within state over time. The fixed-effect model removes bias from factors that vary between states but are constant within states over time, but there might be important variables that vary between states and over time that are omitted from the regression model. For example other policy measures that are related to the implementation of shall issue laws and that affect crime rates.

Second, we might also be concerned about simultaneous causality: if there are many violent crimes this may induce policy makers to change concealed weapons laws.

## 7.3 Homework

**Question 1**

Replicate the seminar analysis for the two other dependent variables in the data: `vio`

and `rob`

. For each variable, do the following:

- Estimate a simple linear regression with
`shall`

as the sole explanatory variable. - Estimate a multiple linear regression with
`shall`

,`pm1029`

,`avginc`

, and`pop`

as explanatory variables. - Estimate a fixed-effect model which includes
`stateid`

plus the explanatory variables from step 2. - Present a table which compares the three models.
- Interpret the
`shall`

coefficient for each of the models you have estimated.

## Reveal answer

```
## Violent crime rate
vio_simple_model <- lm(vio ~ shall, data = guns)
vio_multiple_model <- lm(vio ~ shall + pm1029 + avginc + pop, data = guns)
vio_fe_model <- lm(vio ~ shall + pm1029 + avginc + pop + stateid, data = guns)
screenreg(list(vio_simple_model, vio_multiple_model, vio_fe_model),
omit.coef = "stateid")
## Robbery rate
rob_simple_model <- lm(rob ~ shall, data = guns)
rob_multiple_model <- lm(rob ~ shall + pm1029 + avginc + pop, data = guns)
rob_fe_model <- lm(rob ~ shall + pm1029 + avginc + pop + stateid, data = guns)
screenreg(list(rob_simple_model, rob_multiple_model, rob_fe_model),
omit.coef = "stateid")
```

```
##
## ==================================================
## Model 1 Model 2 Model 3
## --------------------------------------------------
## (Intercept) 502.17 *** 501.70 *** 1170.14 ***
## (8.21) (96.44) (95.05)
## shall -121.12 *** -105.80 *** 2.36
## (16.50) (14.52) (8.61)
## pm1029 -17.08 *** -26.56 ***
## (4.23) (2.76)
## avginc 11.97 *** -5.45
## (2.94) (2.80)
## pop 22.15 *** 10.68 **
## (1.17) (3.95)
## --------------------------------------------------
## R^2 0.04 0.35 0.90
## Adj. R^2 0.04 0.35 0.89
## Num. obs. 1150 1150 1150
## ==================================================
## *** p < 0.001; ** p < 0.01; * p < 0.05
##
## ==================================================
## Model 1 Model 2 Model 3
## --------------------------------------------------
## (Intercept) 158.74 *** -69.50 262.56 ***
## (3.54) (37.23) (40.86)
## shall -60.84 *** -41.01 *** 10.40 **
## (7.12) (5.60) (3.70)
## pm1029 1.82 -3.29 **
## (1.63) (1.19)
## avginc 10.06 *** -5.79 ***
## (1.14) (1.20)
## pop 11.62 *** -0.32
## (0.45) (1.70)
## --------------------------------------------------
## R^2 0.06 0.49 0.90
## Adj. R^2 0.06 0.49 0.90
## Num. obs. 1150 1150 1150
## ==================================================
## *** p < 0.001; ** p < 0.01; * p < 0.05
```

What conclusion do you draw about Lott’s “More Guns, Less Crime” thesis from these analyses?

## Reveal answer

In all three analyses – for the murder rate, the violent crime rate, or the robbery rate – we see that while there are relatively large and significant associations between shall issue laws and the outcomes in the simple and multiple regression models, these effects largely disappear in the fixed-effect models. In the case of the violent crime rate and the robbery rate, the fixed effect model coefficients associated with the

`shall`

variable are actuallypositive, implying that those states with the shall issue laws actually have higher crime rates than other states.

It is worth noting that Lott’s thesis has been widely discredited. To read more, see this paper, or this one, or this one, or this one.↩︎