Project 02Econometrics coursework in R
Econometrics: Panel Data Analysis
A panel-data study in R of whether shall-carry laws are associated with violent-crime rates across 51 US jurisdictions from 1977 to 1999.
My role
I completed the panel-data analysis independently, as part of a larger academic project.
Project overview
Problem
Is a shall-carry law associated with violent-crime rates once differences between states and years are accounted for?
Objective
Choose between fixed and random effects on evidence, check the model's assumptions, and report the law coefficient with uncertainty that allows for correlation within each state.
1,173 observations
Balanced panel of 51 US jurisdictions over 23 years, 1977-1999, AER Guns dataset (opens in a new tab)
Tech stack
Languages and tools
- R
- plm
- nlme
Methods
- Fixed and random effects
- Log transformations
- Hausman test
- Residual diagnostics
- FGLS
Architecture and implementation
An R notebook built with plm and nlme, modelling log violent-crime rates with year indicators in every model.
Prepare the panel
Explore the distributions and log-transform skewed variables. Murder and robbery are left out as explanatory variables, since they are components of the violent-crime outcome.
Investigate multicollinearity
Unusually large fixed-effects standard errors prompted a within-state correlation check. Log population and log density correlate at about 0.9992 within states, so density was removed.
Choose the model
Fixed effects compare each state only with itself over time. Random effects also use differences between states, which is more precise but assumes those differences are unrelated to the explanatory variables. A Hausman test checks whether the two disagree. Both models include year indicators. With p = 0.08924, random effects are retained under the notebook's 5% decision rule. Non-rejection does not prove the random-effects assumptions.
Simplify the model
Controls that were not significant were removed one at a time: prisoners (p = 0.672), income (0.191), population (0.231), and the African-American population share (0.132). The law stays in as the policy variable being studied. The final model has the law, the share of the population that is male and aged 10-29, and year indicators.
Diagnose and correct inference
Residual diagnostics found non-constant variance (Breusch-Pagan p = 0.01136) and non-normal residuals (Jarque-Bera p < 0.001). Standard errors were then clustered by state with the Arellano HC1 estimator, which allows for this and for correlation within each state over time. The coefficients stay the same and only the uncertainty changes.
Explore FGLS
FGLS (feasible generalized least squares) reweights observations by their estimated error variance. An iterative FGLS exercise with nlme converged in four iterations, but its diagnostics still rejected constant variance. It does not reproduce the state random-effects structure of the plm model, so it is treated as an exploration.
Final random-effects model
- Law coefficient
- -0.0321
- State-clustered p-value
- 0.447
An association in observational data, not a causal estimate of the law's effect.
Outcomes and links
p = 0.447
State-clustered p-value for the law coefficient (-0.0321) in the final random-effects model. No statistically significant association was established.
Notebook result
Results
| Law coefficientFinal random-effects model | -0.0321 |
|---|---|
| State-clustered p-valueArellano HC1 standard errors | 0.447 |
| p-value before clusteringSame coefficient, default standard errors | 0.0558 |
| Hausman test p-valueRandom effects retained under a 5% rule | 0.08924 |
| Reported R²Final model | 0.399 |
| Within-state correlationLog population and log density | 0.9992 |
| FGLS iterationsConstant variance still rejected, p = 0.004695 | 4 |
Takeaways and limits
- The analysis does not establish a statistically significant association between the law and violent-crime rates.
- This is observational coursework, not a causal policy evaluation.
- Clustering by state changes the uncertainty, not the estimate, which is why the p-value moves while the coefficient stays the same.
- The FGLS exercise changes the error structure and does not remove every diagnostic concern.
