library(plm)
library(lmtest)
library(sandwich)
library(stargazer)
I used the Guns.csv file, which is the same data as the
Guns dataset in the AER package (Stock and
Watson 2007, Empirical Exercise 10.1; data originally compiled by Ayres
and Donohue 2003). It is a state-year panel covering all 50 states plus
DC for 1977 through 1999.
# Note: knitr uses the folder the .Rmd is saved in as the working directory,
# which is not always the same as your console's working directory. Guns.csv
# needs to be in that same folder, or swap in the full path below.
guns <- read.csv("C:/Users/dbely/OneDrive/Desktop/Econometrics/Week 4/Guns-1-1.csv")
# entity component: state. time component: year
n_states <- length(unique(guns$state))
n_years <- length(unique(guns$year))
n_states
## [1] 51
n_years
## [1] 23
# balance check
table(table(guns$state))
##
## 23
## 51
Every state shows up exactly 23 times, so this is a balanced panel:
51 states times 23 years gives the full 1,173 rows, with no gaps. The
entity dimension is state and the time dimension is
year. law is a dummy for whether the state had
a “shall issue” concealed handgun law in effect that year, which is
really the policy variable of interest here, not just a control.
I’m modeling the violent crime rate as a function of the concealed carry law and a set of standard controls used in this literature: the incarceration rate, population density, income, and the demographic shares:
\[Violent_{it} = \beta_0 + \beta_1 Law_{it} + \beta_2 Prisoners_{it} + \beta_3 Density_{it} + \beta_4 Income_{it} + \beta_5 Male_{it} + \beta_6 AfAm_{it} + \beta_7 Cauc_{it} + u_{it}\]
guns$law01 <- ifelse(guns$law == "yes", 1, 0)
ols_pooled <- lm(violent ~ law01 + prisoners + density + income + male + afam + cauc,
data = guns)
summary(ols_pooled)
##
## Call:
## lm(formula = violent ~ law01 + prisoners + density + income +
## male + afam + cauc, data = guns)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1191.90 -128.21 -33.69 106.49 749.63
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 385.14300 249.17625 1.546 0.122457
## law01 -112.69982 15.03576 -7.495 1.30e-13 ***
## prisoners 0.88502 0.04945 17.897 < 2e-16 ***
## density 70.21716 5.89688 11.908 < 2e-16 ***
## income 0.01649 0.00347 4.751 2.28e-06 ***
## male 16.48430 4.97082 3.316 0.000941 ***
## afam -9.24612 7.60239 -1.216 0.224151
## cauc -8.29201 3.81731 -2.172 0.030041 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 198.2 on 1165 degrees of freedom
## Multiple R-squared: 0.6506, Adjusted R-squared: 0.6485
## F-statistic: 310 on 7 and 1165 DF, p-value: < 2.2e-16
The law coefficient is -112.7 and highly significant (p < .001). Read literally, states with a shall-issue law have a violent crime rate about 113 incidents per 100,000 lower than states without one, holding the controls fixed. That’s a big effect, close to a quarter of the sample mean violent crime rate, and it’s also the exact effect that Lott and Mustard’s “more guns, less crime” argument would predict.
I’m skeptical of taking this at face value though. This is comparing across states, and states differ in a lot of ways that don’t change much over the sample period: baseline gun culture, geography, urban versus rural composition, historical crime levels, general political climate. If those slow-moving state characteristics happen to be correlated with when a state chooses to pass a shall-issue law, this coefficient is picking up some of that correlation rather than a causal policy effect. That’s the classic setup for omitted variable bias in cross-state comparisons, and it’s exactly the kind of bias panel data with entity fixed effects is designed to net out.
The estimating equation with state fixed effects is:
\[Violent_{it} = \alpha_i + \beta_1 Law_{it} + \beta_2 Prisoners_{it} + \beta_3 Density_{it} + \beta_4 Income_{it} + \beta_5 Male_{it} + \beta_6 AfAm_{it} + \beta_7 Cauc_{it} + u_{it}\]
where \(\alpha_i\) absorbs everything about state \(i\) that is constant over 1977-1999.
Method 1: LSDV (n-1 state dummies)
fe_lsdv <- lm(violent ~ law01 + prisoners + density + income + male + afam + cauc
+ factor(state), data = guns)
coef(fe_lsdv)[c("law01","prisoners","density","income","male","afam","cauc")]
## law01 prisoners density income male
## -1.630476e+01 1.317629e-01 -1.402828e+02 -4.272348e-03 -2.327268e+01
## afam cauc
## 1.556026e+01 8.966017e+00
Method 2: entity-demeaned regression
\[(Violent_{it} - \overline{Violent_i}) = \beta_1(Law_{it} - \overline{Law_i}) + ... + (u_{it} - \bar{u_i})\]
demean <- function(x, id) x - ave(x, id)
guns_dm <- data.frame(
violent = demean(guns$violent, guns$state),
law01 = demean(guns$law01, guns$state),
prisoners = demean(guns$prisoners, guns$state),
density = demean(guns$density, guns$state),
income = demean(guns$income, guns$state),
male = demean(guns$male, guns$state),
afam = demean(guns$afam, guns$state),
cauc = demean(guns$cauc, guns$state)
)
fe_demeaned <- lm(violent ~ law01 + prisoners + density + income + male + afam + cauc
- 1, data = guns_dm)
coef(fe_demeaned)
## law01 prisoners density income male
## -1.630476e+01 1.317629e-01 -1.402828e+02 -4.272348e-03 -2.327268e+01
## afam cauc
## 1.556026e+01 8.966017e+00
Method 3: plm() within estimator
fe_plm <- plm(violent ~ law01 + prisoners + density + income + male + afam + cauc,
data = guns, index = c("state","year"), model = "within")
summary(fe_plm)
## Oneway (individual) effect Within Model
##
## Call:
## plm(formula = violent ~ law01 + prisoners + density + income +
## male + afam + cauc, data = guns, model = "within", index = c("state",
## "year"))
##
## Balanced Panel: n = 51, T = 23, N = 1173
##
## Residuals:
## Min. 1st Qu. Median 3rd Qu. Max.
## -785.2153 -48.1402 -2.1384 44.3113 771.8220
##
## Coefficients:
## Estimate Std. Error t-value Pr(>|t|)
## law01 -1.6305e+01 1.1543e+01 -1.4126 0.158059
## prisoners 1.3176e-01 5.5402e-02 2.3783 0.017560 *
## density -1.4028e+02 5.1765e+01 -2.7100 0.006831 **
## income -4.2723e-03 3.6269e-03 -1.1780 0.239060
## male -2.3273e+01 3.9237e+00 -5.9313 4.005e-09 ***
## afam 1.5560e+01 1.0837e+01 1.4359 0.151314
## cauc 8.9660e+00 3.0589e+00 2.9311 0.003446 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Total Sum of Squares: 13576000
## Residual Sum of Squares: 10860000
## R-Squared: 0.20006
## Adj. R-Squared: 0.15916
## F-statistic: 39.836 on 7 and 1115 DF, p-value: < 2.22e-16
All three give the identical law coefficient of -16.30, which is exactly what should happen since they are three algebraically equivalent ways of sweeping out the same entity effect. Compared to the naive OLS estimate, this is roughly an 85% drop in magnitude, and it’s no longer statistically significant (SE 11.5, p = .16 with plain standard errors; the picture is even weaker once I cluster by state, p = .43). The prisoners, density, and demographic coefficients change too, and density and male actually flip sign entirely between the pooled and within-state versions. That sign flip is a real tell that the pooled model was mostly picking up cross-state differences in those variables rather than within-state change over time.
The R² also drops a lot, from .65 in the pooled model to about .20 within. I don’t think that’s a reason to prefer the pooled model though. The entity fixed effects are absorbing all the state-level variation that R² was crediting the controls for in the naive model, so a lower within R² here is a sign the model is doing its job, not doing worse.
stargazer(ols_pooled, fe_lsdv, fe_demeaned, fe_plm, type = "text",
column.labels = c("Pooled OLS","LSDV","Demeaned","plm within"),
omit = "state", omit.labels = "State dummies?")
==========================================================================================================================
Dependent variable:
—————————————————————————————————— violent
OLS panel
linear
Pooled OLS LSDV Demeaned plm within
(1) (2) (3) (4)
————————————————————————————————————————– law01 -112.700*** -16.305
-16.305 -16.305
(15.036) (11.543) (11.287) (11.543)
prisoners 0.885*** 0.132** 0.132** 0.132**
(0.049) (0.055) (0.054) (0.055)
density 70.217*** -140.283*** -140.283*** -140.283***
(5.897) (51.765) (50.620) (51.765)
income 0.016*** -0.004 -0.004 -0.004
(0.003) (0.004) (0.004) (0.004)
male 16.484*** -23.273*** -23.273*** -23.273***
(4.971) (3.924) (3.837) (3.924)
afam -9.246 15.560 15.560 15.560
(7.602) (10.837) (10.597) (10.837)
cauc -8.292** 8.966*** 8.966*** 8.966***
(3.817) (3.059) (2.991) (3.059)
Constant 385.143 321.786
(249.176) (236.426)
| State dummies? No No No No |
Observations 1,173 1,173 1,173 1,173
R2 0.651 0.917 0.200 0.200
Adjusted R2 0.649 0.913 0.195 0.159
Residual Std. Error 198.171 (df = 1165) 98.692 (df = 1115) 96.510 (df =
1166)
F Statistic 309.961*** (df = 7; 1165) 216.323*** (df = 57; 1115)
41.658*** (df = 7; 1166) 39.836*** (df = 7; 1115)
==========================================================================================================================
Note: p<0.1; p<0.05; p<0.01
State fixed effects absorb time-invariant (or very slow-moving) characteristics of each state, things like enduring gun culture, geography, or historical crime baselines, that would otherwise confound the law coefficient. They do not absorb anything that changes over time for all states simultaneously, like a national crime wave or a nationwide trend in policing.
Since the assignment mentioned it’s common to include both, I also ran a two-way version with year fixed effects added:
\[Violent_{it} = \alpha_i + \lambda_t + \beta_1 Law_{it} + ... + u_{it}\]
fe_twoway <- plm(violent ~ law01 + prisoners + density + income + male + afam + cauc,
data = guns, index = c("state","year"), model = "within",
effect = "twoways")
coeftest(fe_twoway, vcov. = function(x) vcovHC(x, type = "HC1", cluster = "group"))
##
## t test of coefficients:
##
## Estimate Std. Error t value Pr(>|t|)
## law01 -0.6540483 19.5972609 -0.0334 0.97338
## prisoners 0.1950755 0.1108579 1.7597 0.07874 .
## density -93.4713246 82.6116913 -1.1315 0.25811
## income 0.0067000 0.0080933 0.8278 0.40794
## male 48.1997116 29.3291230 1.6434 0.10059
## afam -36.7440991 37.7348101 -0.9737 0.33040
## cauc -11.5730937 13.4934149 -0.8577 0.39125
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Adding year effects (which soak up things like the well-documented nationwide decline in crime through the 1990s) shrinks the law coefficient almost to zero, -0.65, with a huge standard error. So in this simple specification there’s no real evidence that shall-issue laws moved violent crime rates once both state and year effects are in the model. That actually lines up with the published literature: Ayres and Donohue (2003) reexamined Lott and Mustard’s original “more guns, less crime” claim using this same state panel and argued the effect is not robust once you take the panel structure seriously (Ayres & Donohue, 2003).
I don’t think this fully settles anything though. I’m still not sure
how much of the remaining variation in law is coming from a
handful of states that adopted the law mid-sample versus states that had
it the whole time or never did, and whether state-specific linear time
trends (on top of year fixed effects) would knock the coefficient around
any further. Has anyone tried adding state-specific trends to their
panel this week, and if so did it change your story much?
Ayres, I., & Donohue, J. J. (2003). Shooting down the “more guns, less crime” hypothesis. Stanford Law Review, 55, 1193-1312.
Stock, J. H., & Watson, M. W. (2007). Introduction to econometrics (2nd ed.). Addison Wesley.