Skip to content
All projects

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.

  1. 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.

  2. 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.

  3. 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.

  4. 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.

  5. 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.

  6. 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.

Full coefficient table

Final random-effects model of log violent-crime rate, with Arellano HC1 standard errors clustered by state

Final random-effects model of log violent-crime rate, with Arellano HC1 standard errors clustered by state
TermEstimateStd. errort valuePr(>|t|)Signif.
(Intercept)4.33492220.58307297.43462.045e-13***
lawyes-0.03211840.0422381-0.76040.4471648
male0.08023770.03030412.64780.0082139**
year19780.06132980.00966696.34433.208e-10***
year19790.16908200.015930110.6140< 2.2e-16***
year19800.22454090.02453789.1508< 2.2e-16***
year19810.22654150.02712518.3517< 2.2e-16***
year19820.20591070.03002336.85841.136e-11***
year19830.17163410.03660844.68843.084e-06***
year19840.20778430.04611394.50597.285e-06***
year19850.26063450.05544204.70102.902e-06***
year19860.34170050.06703795.09714.030e-07***
year19870.34397050.07824194.39621.203e-05***
year19880.40917200.08468814.83151.538e-06***
year19890.46723020.09266475.04225.345e-07***
year19900.58855090.10155005.79578.783e-09***
year19910.64439630.10779275.97813.010e-09***
year19920.67936640.11490005.91274.435e-09***
year19930.70412000.11858165.93793.822e-09***
year19940.69326730.12316825.62862.282e-08***
year19950.69007230.12472375.53283.902e-08***
year19960.63788460.12938434.93029.425e-07***
year19970.62039700.13176154.70852.800e-06***
year19980.56771290.13437104.22502.579e-05***
year19990.51151200.13988773.65660.0002672***

Saved notebook output, shown as recorded. Signif. codes: *** p < 0.001, ** p < 0.01.

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

Results for Econometrics: Panel Data Analysis
Law coefficientFinal random-effects model-0.0321
State-clustered p-valueArellano HC1 standard errors0.447
p-value before clusteringSame coefficient, default standard errors0.0558
Hausman test p-valueRandom effects retained under a 5% rule0.08924
Reported R²Final model0.399
Within-state correlationLog population and log density0.9992
FGLS iterationsConstant variance still rejected, p = 0.0046954

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.