Econometrics notebook

Econometrics: Panel Data Analysis

Read-only preview of the saved R notebook. Code is collapsed, and figures and results are from the original run. Nothing is executed here.

Panel Data Analysis – Guns Dataset

בחלק זה נבצע ניתוח נתוני פאנל באמצעות מודלי Fixed Effects (FE) ו-Random Effects (RE).

מטרת הניתוח היא לבחון את הקשר בין שיעור הפשיעה האלימה במדינות ארה"ב לבין משתנים דמוגרפיים, כלכליים ומשתני מדיניות לאורך זמן, ולבחור בין שני המודלים באמצעות מבחן Hausman.

לאחר בחירת המודל נבחן את שאריותיו ונבדוק האם קיימות בעיות במפרט המודל.

Show code, cell 1
In [4]:
# Packages

library(AER)
library(plm)
library(corrplot)
library(lmtest)
library(tseries)
library(nlme)
Show code, cell 2
In [6]:
# Load the dataset

data("Guns", package = "AER")

guns <- Guns

1. Data Description

הניתוח מבוסס על מאגר הנתונים Guns מספריית AER ב-R.

זהו מאגר נתוני פאנל המתאר את 50 מדינות ארה"ב ואת מחוז קולומביה לאורך השנים 1977–1999. כל תצפית מייצגת מדינה מסוימת בשנה מסוימת.

המשתנה המוסבר בניתוח הוא violent, המייצג את שיעור מקרי הפשיעה האלימה ל-100,000 תושבים. מטרת הניתוח היא לבחון כיצד שיעור זה קשור למאפיינים דמוגרפיים וכלכליים של המדינה ולמשתנה law, המציין האם חוק Shall-Carry היה בתוקף במדינה באותה שנה.

המשתנים במאגר הם:

  • state – המדינה.
  • year – שנת התצפית.
  • violent – שיעור מקרי פשיעה אלימה ל-100,000 תושבים.
  • murder – שיעור מקרי רצח ל-100,000 תושבים.
  • robbery – שיעור מקרי שוד ל-100,000 תושבים.
  • prisoners – שיעור האסירים שנידונו למאסר ל-100,000 תושבים, בשנה הקודמת.
  • afam – אחוז האוכלוסייה האפרו-אמריקאית בגילאי 10–64.
  • cauc – אחוז האוכלוסייה הקווקזית בגילאי 10–64.
  • male – אחוז הגברים בגילאי 10–29.
  • population – אוכלוסיית המדינה, במיליוני תושבים.
  • income – הכנסה אישית ריאלית לנפש.
  • density – צפיפות אוכלוסייה לשטח.
  • law – האם חוק Shall-Carry היה בתוקף במדינה ובשנה הנתונה.
Show code, cell 3
In [9]:
# Inspect the data

head(guns)
str(guns)
summary(guns)
dim(guns)
A data.frame: 6 × 13
yearviolentmurderrobberyprisonersafamcaucmalepopulationincomedensitystatelaw
<fct><dbl><dbl><dbl><int><dbl><dbl><dbl><dbl><dbl><dbl><fct><fct>
11977414.414.2 96.8 838.38487355.1229118.174413.7804039563.1480.0745524Alabamano
21978419.113.3 99.1 948.35210155.1436717.994083.8318389932.0000.0755667Alabamano
31979413.313.2109.51448.32957555.1358617.839343.8662489877.0280.0762453Alabamano
41980448.513.2132.11418.40838654.9125917.734203.9003689541.4280.0768288Alabamano
51981470.511.9126.51498.48343554.9251317.673723.9185319548.3510.0771866Alabamano
61982447.710.6112.01838.51400054.8962117.510523.9252299478.9190.0773185Alabamano
'data.frame':	1173 obs. of  13 variables:
 $ year      : Factor w/ 23 levels "1977","1978",..: 1 2 3 4 5 6 7 8 9 10 ...
 $ violent   : num  414 419 413 448 470 ...
 $ murder    : num  14.2 13.3 13.2 13.2 11.9 10.6 9.2 9.4 9.8 10.1 ...
 $ robbery   : num  96.8 99.1 109.5 132.1 126.5 ...
 $ prisoners : int  83 94 144 141 149 183 215 243 256 267 ...
 $ afam      : num  8.38 8.35 8.33 8.41 8.48 ...
 $ cauc      : num  55.1 55.1 55.1 54.9 54.9 ...
 $ male      : num  18.2 18 17.8 17.7 17.7 ...
 $ population: num  3.78 3.83 3.87 3.9 3.92 ...
 $ income    : num  9563 9932 9877 9541 9548 ...
 $ density   : num  0.0746 0.0756 0.0762 0.0768 0.0772 ...
 $ state     : Factor w/ 51 levels "Alabama","Alaska",..: 1 1 1 1 1 1 1 1 1 1 ...
 $ law       : Factor w/ 2 levels "no","yes": 1 1 1 1 1 1 1 1 1 1 ...
      year        violent           murder          robbery      
 1977   : 51   Min.   :  47.0   Min.   : 0.200   Min.   :   6.4  
 1978   : 51   1st Qu.: 283.1   1st Qu.: 3.700   1st Qu.:  71.1  
 1979   : 51   Median : 443.0   Median : 6.400   Median : 124.1  
 1980   : 51   Mean   : 503.1   Mean   : 7.665   Mean   : 161.8  
 1981   : 51   3rd Qu.: 650.9   3rd Qu.: 9.800   3rd Qu.: 192.7  
 1982   : 51   Max.   :2921.8   Max.   :80.600   Max.   :1635.1  
 (Other):867                                                     
   prisoners           afam              cauc            male      
 Min.   :  19.0   Min.   : 0.2482   Min.   :21.78   Min.   :12.21  
 1st Qu.: 114.0   1st Qu.: 2.2022   1st Qu.:59.94   1st Qu.:14.65  
 Median : 187.0   Median : 4.0262   Median :65.06   Median :15.90  
 Mean   : 226.6   Mean   : 5.3362   Mean   :62.95   Mean   :16.08  
 3rd Qu.: 291.0   3rd Qu.: 6.8507   3rd Qu.:69.20   3rd Qu.:17.53  
 Max.   :1913.0   Max.   :26.9796   Max.   :76.53   Max.   :22.35  
                                                                   
   population          income         density                 state     
 Min.   : 0.4028   Min.   : 8555   Min.   :7.071e-04   Alabama   :  23  
 1st Qu.: 1.1877   1st Qu.:11935   1st Qu.:3.191e-02   Alaska    :  23  
 Median : 3.2713   Median :13402   Median :8.157e-02   Arizona   :  23  
 Mean   : 4.8163   Mean   :13725   Mean   :3.520e-01   Arkansas  :  23  
 3rd Qu.: 5.6856   3rd Qu.:15271   3rd Qu.:1.777e-01   California:  23  
 Max.   :33.1451   Max.   :23647   Max.   :1.110e+01   Colorado  :  23  
                                                       (Other)   :1035  
  law     
 no :888  
 yes:285  
          
          
          
          
          
  1. 1173
  2. 13

2. Data Preparation and Panel Structure

בשלב זה בחנו את מבנה מאגר הנתונים ואת הסטטיסטיקה התיאורית של המשתנים, ובדקנו האם קיימים ערכים חסרים.

בנוסף, הגדרנו את state כממד הרוחבי ואת year כממד הזמן.

במקרה שלנו, כל מדינה היא יחידה נפרדת וכל שנה היא תקופת זמן.

המשתנה year כבר מוגדר במאגר כמשתנה מסוג factor בעל 23 רמות. לכן כאשר הוא נכלל במודל, R יוצר באופן אוטומטי משתני דמה לשנים, כאשר שנת 1977 משמשת כקטגוריית הבסיס.

Show code, cell 4
In [12]:
# Check for missing values

anyNA(guns)
colSums(is.na(guns))

# Create a panel data frame

guns_panel <- pdata.frame(
  guns,
  index = c("state", "year")
)

# Check the panel structure

pdim(guns_panel)
FALSE
year0violent0murder0robbery0prisoners0afam0cauc0male0population0income0density0state0law0
Balanced Panel: n = 51, T = 23, N = 1173

המאגר כולל 1,173 תצפיות ו-13 משתנים, המתקבלים מ-51 מדינות הנצפות במשך 23 שנים.

לא נמצאו ערכים חסרים במאגר.

בנוסף, נמצא כי מדובר ב- Balanced Panel, כלומר לכל אחת מ-51 המדינות קיימת תצפית בכל אחת מ-23 השנים.

לכן ניתן להמשיך לניתוח ללא צורך בהסרת תצפיות עקב ערכים חסרים או חוסר איזון במבנה הפאנל.

3. Exploratory Data Analysis

לפני הגדרת מודלי Fixed Effects ו-Random Effects, בחנו את ההתפלגויות של המשתנה המוסבר ושל המשתנים הרציפים שעשויים להיכלל במודל.

מטרת הבדיקה היא לזהות משתנים בעלי התפלגות מוטה מאוד או פערים גדולים בסדרי הגודל, ולבחון האם טרנספורמציית log עשויה להתאים להם.

בשלב זה איננו דורשים שהמשתנים המסבירים עצמם יתפלגו נורמלית. ההיסטוגרמות משמשות בעיקר לבחינת צורת ההתפלגות ולבחינת הצורך בטרנספורמציה.

Show code, cell 5
In [16]:
options(repr.plot.width = 16, repr.plot.height = 12)
par(mfrow = c(2, 2))

hist(guns$violent,
     main = "Violent Crime Rate",
     xlab = "violent")

hist(guns$prisoners,
     main = "Prisoners",
     xlab = "prisoners")

hist(guns$population,
     main = "Population",
     xlab = "population")

hist(guns$income,
     main = "Income",
     xlab = "income")

par(mfrow = c(1, 1))
No description has been provided for this image
Show code, cell 6
In [27]:
options(repr.plot.width = 16, repr.plot.height = 12)
par(mfrow = c(2, 2))

hist(guns$density,
     main = "Population Density",
     xlab = "density")

hist(guns$afam,
     main = "African-American Population",
     xlab = "afam")

hist(guns$cauc,
     main = "Caucasian Population",
     xlab = "cauc")

hist(guns$male,
     main = "Young Male Population",
     xlab = "male")

par(mfrow = c(1, 1))
No description has been provided for this image

4. Log Transformation

מההיסטוגרמות ניתן לראות כי violent, prisoners, population ו-density מאופיינים בהטיה משמעותית ימינה.

לכן נבצע עבור משתנים אלה טרנספורמציית log.

לבחירה זו יש שתי מטרות. מבחינה סטטיסטית, הלוגריתם מצמצם את השפעתם של ערכים גבוהים מאוד ומקרב את המשתנים לסקאלה מאוזנת יותר. מבחינה כלכלית, הוא גם מאפשר לפרש קשרים יחסיים, כאשר גם המשתנה המוסבר וגם מסביר מסוים נמצאים בלוגריתם, המקדם של אותו מסביר ניתן לפרש כגמישות בקירוב - אחוז השינוי ב-violent הקשור לעלייה של 1% במסביר, בהינתן יתר המשתנים.

לאחר הטרנספורמציה נבחן מחדש את ההתפלגויות כדי לוודא שהשינוי אכן שיפר את צורתן.

המשתנים income, afam, cauc ו-male יישארו בשלב זה בסקאלה המקורית, משום שלא נצפתה עבורם הטיה המצדיקה טרנספורמציה דומה.

Show code, cell 7
In [30]:
# Log transformations for right-skewed variables

guns$log_violent    <- log(guns$violent)
guns$log_prisoners  <- log(guns$prisoners)
guns$log_population <- log(guns$population)
guns$log_density    <- log(guns$density)
Show code, cell 8
In [32]:
options(repr.plot.width = 16, repr.plot.height = 12)

par(mfrow = c(2, 2))

hist(guns$log_violent,
     main = "Log Violent Crime Rate",
     xlab = "log(violent)")

hist(guns$log_prisoners,
     main = "Log Prisoners",
     xlab = "log(prisoners)")

hist(guns$log_population,
     main = "Log Population",
     xlab = "log(population)")

hist(guns$log_density,
     main = "Log Population Density",
     xlab = "log(density)")

par(mfrow = c(1, 1))
No description has been provided for this image

לאחר ביצוע טרנספורמציית log ניתן לראות שיפור ברור בהתפלגויות של ארבעת המשתנים.

ההטיה החזקה ימינה של violent ו-prisoners הצטמצמה משמעותית, ושתי ההתפלגויות הפכו סימטריות יותר.

גם עבור population ו-density הטרנספורמציה צמצמה באופן משמעותי את הפערים בין הערכים ואת ההטיה שנצפתה בנתונים המקוריים.

לכן בהמשך הניתוח נשתמש ב- log(violent) כמשתנה המוסבר, וב- log(prisoners), log(population) ו-log(density) כגרסאות של המשתנים המסבירים המתאימים.

5. Correlation and Multicollinearity

לפני הגדרת מודלי הפאנל נבחן את הקשרים בין המשתנים המסבירים הרציפים.

מטרת הבדיקה היא לזהות זוגות של משתנים בעלי מתאם גבוה מאוד, אשר עלולים ליצור בעיית multicollinearity ולהקשות על הפרדת ההשפעה של כל אחד מהם במודל.

המשתנים murder ו-robbery אינם נכללים כמסבירים, מכיוון שהם מתארים סוגים של פשיעה הנכללים במדד הפשיעה האלימה שאותו אנו מנסים להסביר.

Show code, cell 9
In [36]:
# Correlation matrix

cor_data <- guns[, c(
  "log_prisoners",
  "afam",
  "cauc",
  "male",
  "log_population",
  "income",
  "log_density"
)]

cor_matrix <- cor(cor_data)

round(cor_matrix, 2)
A matrix: 7 × 7 of type dbl
log_prisonersafamcaucmalelog_populationincomelog_density
log_prisoners 1.00 0.48-0.46-0.54 0.20 0.44 0.22
afam 0.48 1.00-0.98 0.02 0.03 0.26 0.41
cauc-0.46-0.98 1.00-0.01-0.05-0.19-0.42
male-0.54 0.02-0.01 1.00-0.15-0.53-0.24
log_population 0.20 0.03-0.05-0.15 1.00 0.11 0.43
income 0.44 0.26-0.19-0.53 0.11 1.00 0.38
log_density 0.22 0.41-0.42-0.24 0.43 0.38 1.00
Show code, cell 10
In [38]:
options(repr.plot.width = 14, repr.plot.height = 12)

corrplot(
  cor_matrix,
  method = "number",
  type = "upper",
  tl.cex = 1.1,
  number.cex = 1,
  number.digits = 2
)
No description has been provided for this image

מטריצת המתאמים מצביעה על מתאם שלילי גבוה מאוד בין afam ל-cauc, כאשר מקדם המתאם הוא -0.98.

כדי לשמור על מפרט חסכוני ולהימנע מ- multicollinearity נשאיר את afam כמשתנה המייצג היבט זה של ההרכב הדמוגרפי ונשמיט את cauc. הבחירה אינה טענה שלפיה אחד המשתנים חשוב כלכלית יותר מהשני, היא נועדה למנוע ייצוג כפול של מידע כמעט זהה.

שאר המתאמים בין המשתנים המסבירים הם מתונים יותר, ולכן בשלב זה אין הצדקה להסיר משתנים נוספים על סמך מטריצת המתאמים בלבד.

6. Model Specification

לאחר שלבי הכנת הנתונים, הטרנספורמציות ובדיקת המתאמים, נגדיר את המפרט הראשוני של מודלי הפאנל.

המשתנה המוסבר הוא log_violent.

המשתנים המסבירים כוללים את משתנה המדיניות law, את המשתנים הדמוגרפיים afam ו-male, את המשתנים הכלכליים והמבניים log_prisoners, log_population, income ו-log_density, וכן משתני שנה לצורך שליטה בשינויים משותפים לכל המדינות לאורך זמן.

המשתנים murder ו-robbery אינם נכללים במודל משום שהם מתארים סוגי פשיעה הנכללים במדד violent שאותו אנו מנסים להסביר.

המשתנה cauc אינו נכלל בעקבות המתאם הגבוה עם afam.

Initial Model Equation

בהתאם לבחירת המשתנים ולטרנספורמציות שבוצעו, המפרט הראשוני של המודל הוא:

$$ \ln(violent_{it}) = \alpha + \beta_1 law_{it} + \beta_2 \ln(prisoners_{it}) + \beta_3 afam_{it} + \beta_4 male_{it} + \beta_5 \ln(population_{it}) + \beta_6 income_{it} + \beta_7 \ln(density_{it}) + \sum_{t=1978}^{1999}\gamma_t D_t + \varepsilon_{it} $$

כאשר:

  • $i$ מייצג מדינה.
  • $t$ מייצג שנה.
  • $violent_{it}$ הוא שיעור הפשיעה האלימה במדינה $i$ בשנה $t$.
  • $D_t$ הם משתני דמה לשנים, כאשר שנת 1977 משמשת כשנת הבסיס.
  • $\beta_1,\ldots,\beta_7$ הם המקדמים של המשתנים המסבירים.
  • $\gamma_t$ מייצגים את השפעות השנים.
  • $\varepsilon_{it}$ הוא רכיב השגיאה.
Show code, cell 11
In [43]:
# Initial panel model specification

formula_initial <- log_violent ~
  law +
  log_prisoners +
  afam +
  male +
  log_population +
  income +
  log_density +
  year

7. Fixed Effects and Random Effects Models

כעת נאמוד את שני מודלי הפאנל על בסיס אותו מפרט ראשוני.

מודל Fixed Effects (FE) מאפשר לאפקטים הבלתי נצפים והקבועים של כל מדינה להיות מתואמים עם המשתנים המסבירים. האמידה מבוססת על השינויים המתרחשים בתוך אותה מדינה לאורך זמן.

מודל Random Effects (RE) מניח שהאפקט הייחודי של כל מדינה אינו מתואם עם המשתנים המסבירים.

בשלב זה נאמוד את שני המודלים על אותו מפרט ונבחן את תוצאותיהם.

אם תזוהה בעיה מבנית במפרט המשותף לשני המודלים, כגון multicollinearity חזקה, נטפל בה לפני ההשוואה.

לאחר קביעת מפרט משותף תקין נשתמש במבחן Hausman לבחירה בין FE ל-RE. סינון המשתנים לפי רמת מובהקות יתבצע לאחר מכן במודל שנבחר.

Fixed Effects Model

$$ \ln(violent_{it}) = \alpha_i + X_{it}'\beta + \sum_{t=1978}^{1999}\gamma_t D_t + \varepsilon_{it} $$

במודל Fixed Effects לכל מדינה קיים אפקט קבוע משלה, $\alpha_i$. כך ניתן לשלוט במאפיינים בלתי נצפים של המדינה שאינם משתנים לאורך זמן, גם כאשר הם מתואמים עם המשתנים המסבירים.

Random Effects Model

$$ \ln(violent_{it}) = \alpha + X_{it}'\beta + \sum_{t=1978}^{1999}\gamma_t D_t + \mu_i + \varepsilon_{it} $$

במודל Random Effects ההבדל הייחודי בין המדינות מיוצג באמצעות $\mu_i$, שהוא רכיב אקראי של המדינה.

ההנחה המרכזית של מודל זה היא שהאפקט הייחודי למדינה אינו מתואם עם המשתנים המסבירים:

$$ Cov(\mu_i,X_{it})=0 $$

מבחן Hausman ישמש בהמשך לבחינת התאמת הנחה זו ולבחירה בין שני המודלים.

Show code, cell 12
In [47]:
# Fixed Effects model

fe_initial <- plm(
  formula_initial,
  data = guns,
  index = c("state", "year"),
  model = "within"
)

summary(fe_initial)
Oneway (individual) effect Within Model

Call:
plm(formula = formula_initial, data = guns, model = "within", 
    index = c("state", "year"))

Balanced Panel: n = 51, T = 23, N = 1173

Residuals:
      Min.    1st Qu.     Median    3rd Qu.       Max. 
-0.4439993 -0.0783511  0.0047374  0.0789669  0.6795281 

Coefficients:
                  Estimate  Std. Error t-value  Pr(>|t|)    
lawyes         -2.8036e-02  1.7354e-02 -1.6155 0.1064826    
log_prisoners  -1.0038e-01  2.7939e-02 -3.5929 0.0003416 ***
afam           -7.1718e-03  1.0982e-02 -0.6530 0.5138790    
male            7.7340e-02  1.1293e-02  6.8486 1.242e-11 ***
log_population  4.5431e-01  1.3025e+00  0.3488 0.7273123    
income          2.7423e-06  6.1901e-06  0.4430 0.6578392    
log_density    -6.8362e-01  1.3150e+00 -0.5199 0.6032725    
year1978        6.6651e-02  2.7825e-02  2.3953 0.0167726 *  
year1979        1.8490e-01  2.8192e-02  6.5587 8.358e-11 ***
year1980        2.4706e-01  2.8463e-02  8.6800 < 2.2e-16 ***
year1981        2.5483e-01  2.9091e-02  8.7598 < 2.2e-16 ***
year1982        2.4767e-01  3.0731e-02  8.0594 1.996e-15 ***
year1983        2.2548e-01  3.3088e-02  6.8145 1.560e-11 ***
year1984        2.6672e-01  3.5930e-02  7.4233 2.292e-13 ***
year1985        3.2463e-01  3.8814e-02  8.3637 < 2.2e-16 ***
year1986        4.1205e-01  4.2406e-02  9.7168 < 2.2e-16 ***
year1987        4.2034e-01  4.5912e-02  9.1552 < 2.2e-16 ***
year1988        4.9126e-01  4.9628e-02  9.8990 < 2.2e-16 ***
year1989        5.5570e-01  5.3167e-02 10.4520 < 2.2e-16 ***
year1990        6.9005e-01  5.6364e-02 12.2428 < 2.2e-16 ***
year1991        7.5413e-01  5.9185e-02 12.7419 < 2.2e-16 ***
year1992        7.9616e-01  6.2477e-02 12.7432 < 2.2e-16 ***
year1993        8.2778e-01  6.4733e-02 12.7877 < 2.2e-16 ***
year1994        8.2324e-01  6.7360e-02 12.2214 < 2.2e-16 ***
year1995        8.2840e-01  7.0212e-02 11.7986 < 2.2e-16 ***
year1996        7.8340e-01  7.3044e-02 10.7250 < 2.2e-16 ***
year1997        7.7190e-01  7.5635e-02 10.2056 < 2.2e-16 ***
year1998        7.2570e-01  7.8486e-02  9.2463 < 2.2e-16 ***
year1999        6.7540e-01  8.0617e-02  8.3779 < 2.2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Total Sum of Squares:    36.789
Residual Sum of Squares: 21.143
R-Squared:      0.4253
Adj. R-Squared: 0.38376
F-statistic: 27.8915 on 29 and 1093 DF, p-value: < 2.22e-16
Show code, cell 13
In [49]:
# Random Effects model

re_initial <- plm(
  formula_initial,
  data = guns,
  index = c("state", "year"),
  model = "random"
)

summary(re_initial)
Oneway (individual) effect Random Effect Model 
   (Swamy-Arora's transformation)

Call:
plm(formula = formula_initial, data = guns, model = "random", 
    index = c("state", "year"))

Balanced Panel: n = 51, T = 23, N = 1173

Effects:
                  var std.dev share
idiosyncratic 0.01934 0.13908 0.195
individual    0.08006 0.28295 0.805
theta: 0.898

Residuals:
      Min.    1st Qu.     Median    3rd Qu.       Max. 
-0.5272917 -0.0868476  0.0066143  0.0914545  0.6896996 

Coefficients:
                  Estimate  Std. Error z-value  Pr(>|z|)    
(Intercept)     4.1693e+00  2.8042e-01 14.8682 < 2.2e-16 ***
lawyes         -3.3897e-02  1.8156e-02 -1.8670  0.061901 .  
log_prisoners   1.1240e-02  2.7985e-02  0.4017  0.687941    
afam            2.4356e-02  7.6116e-03  3.1999  0.001375 ** 
male            7.5992e-02  1.1651e-02  6.5224 6.918e-11 ***
log_population  1.1248e-01  4.2553e-02  2.6433  0.008210 ** 
income          1.1084e-05  6.1940e-06  1.7895  0.073533 .  
log_density     6.1650e-02  3.2553e-02  1.8938  0.058247 .  
year1978        5.1505e-02  2.9676e-02  1.7356  0.082640 .  
year1979        1.5491e-01  2.9958e-02  5.1710 2.329e-07 ***
year1980        2.0945e-01  3.0186e-02  6.9386 3.961e-12 ***
year1981        2.0710e-01  3.0720e-02  6.7413 1.570e-11 ***
year1982        1.8189e-01  3.2175e-02  5.6531 1.576e-08 ***
year1983        1.4012e-01  3.4284e-02  4.0870 4.371e-05 ***
year1984        1.6499e-01  3.6842e-02  4.4784 7.519e-06 ***
year1985        2.1031e-01  3.9527e-02  5.3207 1.034e-07 ***
year1986        2.8359e-01  4.2902e-02  6.6100 3.842e-11 ***
year1987        2.7897e-01  4.6224e-02  6.0352 1.588e-09 ***
year1988        3.3629e-01  4.9734e-02  6.7619 1.362e-11 ***
year1989        3.8660e-01  5.3058e-02  7.2864 3.184e-13 ***
year1990        5.0215e-01  5.6492e-02  8.8887 < 2.2e-16 ***
year1991        5.5516e-01  5.9235e-02  9.3721 < 2.2e-16 ***
year1992        5.8184e-01  6.2295e-02  9.3401 < 2.2e-16 ***
year1993        6.0154e-01  6.4392e-02  9.3418 < 2.2e-16 ***
year1994        5.8386e-01  6.6826e-02  8.7370 < 2.2e-16 ***
year1995        5.7472e-01  6.9467e-02  8.2733 < 2.2e-16 ***
year1996        5.1602e-01  7.2071e-02  7.1599 8.071e-13 ***
year1997        4.9087e-01  7.4396e-02  6.5981 4.165e-11 ***
year1998        4.2789e-01  7.6883e-02  5.5656 2.613e-08 ***
year1999        3.6428e-01  7.8725e-02  4.6272 3.706e-06 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Total Sum of Squares:    41.486
Residual Sum of Squares: 25.257
R-Squared:      0.39119
Adj. R-Squared: 0.37575
Chisq: 734.448 on 29 DF, p-value: < 2.22e-16

8. Specification Refinement Before Hausman

תוצאות המודלים הראשוניים הראו Standard Errors גדולים במיוחד עבור log_population ו-log_density במודל Fixed Effects.

מאחר שאמידת FE מבוססת על השינויים בתוך כל מדינה לאורך זמן, נבדוק האם שני המשתנים כמעט נעים יחד בתוך אותה מדינה.

מטרת שלב זה אינה לסנן משתנים לפי מובהקות, אלא לוודא שהמפרט המשותף שישמש להשוואת FE ו-RE אינו סובל מבעיית multicollinearity .

Show code, cell 14
In [52]:
# Check within-state correlation between population and density

log_population_within <- guns$log_population -
  ave(guns$log_population, guns$state)

log_density_within <- guns$log_density -
  ave(guns$log_density, guns$state)

cor(log_population_within, log_density_within)
0.999197995549733

המתאם בין השינויים בתוך המדינה של log_population ושל log_density עומד על 0.9992, ומצביע על כך ששני המשתנים מכילים כמעט אותו מידע מבחינת השונות לאורך זמן.

שטחה של כל מדינה כמעט קבוע לאורך תקופת המדגם. לכן, בתוך אותה מדינה, שינוי בצפיפות משקף כמעט באופן מלא שינוי בגודל האוכלוסייה.

מאחר שמודל Fixed Effects מזהה את המקדמים מתוך השינויים בתוך כל מדינה לאורך זמן, הכללת שני המשתנים יחד יוצרת multicollinearity כמעט מושלמת. תוצאה זו מסבירה את ה- Standard Errors הגדולים שהתקבלו עבורם באמידה הראשונית.

לפיכך, נסיר את log_density ונשאיר את log_population. בחירה זו מונעת כפילות מידע ומאפשרת לשמור במודל מדד ישיר וברור לגודל האוכלוסייה של המדינה.

לאחר הסרת log_density ניתן לאמוד מחדש את מודלי Fixed Effects ו-Random Effects על בסיס מפרט משותף ויציב יותר, ולאחר מכן להשוות ביניהם באמצעות מבחן Hausman.

Show code, cell 15
In [55]:
# Reduced model specification after removing within multicollinearity

formula_reduced <- log_violent ~
  law +
  log_prisoners +
  afam +
  male +
  log_population +
  income +
  year
Show code, cell 16
In [57]:
# Fixed Effects reduced model

fe_reduced <- plm(
  formula_reduced,
  data = guns,
  index = c("state", "year"),
  model = "within"
)

summary(fe_reduced)
Oneway (individual) effect Within Model

Call:
plm(formula = formula_reduced, data = guns, model = "within", 
    index = c("state", "year"))

Balanced Panel: n = 51, T = 23, N = 1173

Residuals:
      Min.    1st Qu.     Median    3rd Qu.       Max. 
-0.4438817 -0.0783732  0.0047202  0.0789621  0.6804231 

Coefficients:
                  Estimate  Std. Error t-value  Pr(>|t|)    
lawyes         -2.9202e-02  1.7202e-02 -1.6976 0.0898723 .  
log_prisoners  -1.0194e-01  2.7768e-02 -3.6709 0.0002534 ***
afam           -7.4590e-03  1.0965e-02 -0.6803 0.4964824    
male            7.8448e-02  1.1086e-02  7.0764 2.639e-12 ***
log_population -2.2189e-01  6.7885e-02 -3.2686 0.0011144 ** 
income          2.0050e-06  6.0234e-06  0.3329 0.7392983    
year1978        6.7160e-02  2.7799e-02  2.4159 0.0158577 *  
year1979        1.8557e-01  2.8153e-02  6.5915 6.756e-11 ***
year1980        2.4720e-01  2.8452e-02  8.6883 < 2.2e-16 ***
year1981        2.5519e-01  2.9073e-02  8.7776 < 2.2e-16 ***
year1982        2.4840e-01  3.0688e-02  8.0943 1.523e-15 ***
year1983        2.2680e-01  3.2978e-02  6.8775 1.023e-11 ***
year1984        2.6889e-01  3.5674e-02  7.5374 1.003e-13 ***
year1985        3.2741e-01  3.8430e-02  8.5198 < 2.2e-16 ***
year1986        4.1553e-01  4.1857e-02  9.9274 < 2.2e-16 ***
year1987        4.2444e-01  4.5214e-02  9.3873 < 2.2e-16 ***
year1988        4.9600e-01  4.8766e-02 10.1711 < 2.2e-16 ***
year1989        5.6102e-01  5.2156e-02 10.7565 < 2.2e-16 ***
year1990        6.9441e-01  5.5717e-02 12.4633 < 2.2e-16 ***
year1991        7.5874e-01  5.8496e-02 12.9707 < 2.2e-16 ***
year1992        8.0128e-01  6.1677e-02 12.9915 < 2.2e-16 ***
year1993        8.3312e-01  6.3890e-02 13.0401 < 2.2e-16 ***
year1994        8.2895e-01  6.6436e-02 12.4774 < 2.2e-16 ***
year1995        8.3451e-01  6.9201e-02 12.0592 < 2.2e-16 ***
year1996        7.8993e-01  7.1933e-02 10.9815 < 2.2e-16 ***
year1997        7.7886e-01  7.4417e-02 10.4662 < 2.2e-16 ***
year1998        7.3320e-01  7.7126e-02  9.5064 < 2.2e-16 ***
year1999        6.8322e-01  7.9173e-02  8.6295 < 2.2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Total Sum of Squares:    36.789
Residual Sum of Squares: 21.148
R-Squared:      0.42516
Adj. R-Squared: 0.38417
F-statistic: 28.8973 on 28 and 1094 DF, p-value: < 2.22e-16
Show code, cell 17
In [59]:
# Random Effects reduced model

re_reduced <- plm(
  formula_reduced,
  data = guns,
  index = c("state", "year"),
  model = "random"
)

summary(re_reduced)
Oneway (individual) effect Random Effect Model 
   (Swamy-Arora's transformation)

Call:
plm(formula = formula_reduced, data = guns, model = "random", 
    index = c("state", "year"))

Balanced Panel: n = 51, T = 23, N = 1173

Effects:
                  var std.dev share
idiosyncratic 0.01933 0.13904 0.197
individual    0.07865 0.28045 0.803
theta: 0.8972

Residuals:
      Min.    1st Qu.     Median    3rd Qu.       Max. 
-0.5189354 -0.0840227  0.0078915  0.0929493  0.6957402 

Coefficients:
                  Estimate  Std. Error z-value  Pr(>|z|)    
(Intercept)     3.9799e+00  2.6381e-01 15.0864 < 2.2e-16 ***
lawyes         -3.1401e-02  1.8144e-02 -1.7307   0.08351 .  
log_prisoners   1.1883e-02  2.8023e-02  0.4240   0.67154    
afam            3.0035e-02  7.0276e-03  4.2739 1.921e-05 ***
male            7.2407e-02  1.1523e-02  6.2837 3.305e-10 ***
log_population  1.5705e-01  3.5848e-02  4.3811 1.181e-05 ***
income          1.2652e-05  6.1540e-06  2.0559   0.03979 *  
year1978        5.0102e-02  2.9731e-02  1.6852   0.09195 .  
year1979        1.5293e-01  3.0006e-02  5.0967 3.457e-07 ***
year1980        2.0727e-01  3.0232e-02  6.8561 7.077e-12 ***
year1981        2.0426e-01  3.0755e-02  6.6414 3.106e-11 ***
year1982        1.7803e-01  3.2190e-02  5.5306 3.191e-08 ***
year1983        1.3476e-01  3.4262e-02  3.9333 8.380e-05 ***
year1984        1.5742e-01  3.6740e-02  4.2848 1.829e-05 ***
year1985        2.0100e-01  3.9354e-02  5.1075 3.265e-07 ***
year1986        2.7236e-01  4.2647e-02  6.3864 1.699e-10 ***
year1987        2.6598e-01  4.5889e-02  5.7961 6.786e-09 ***
year1988        3.2145e-01  4.9310e-02  6.5189 7.084e-11 ***
year1989        3.7008e-01  5.2555e-02  7.0417 1.899e-12 ***
year1990        4.8435e-01  5.5944e-02  8.6577 < 2.2e-16 ***
year1991        5.3646e-01  5.8657e-02  9.1456 < 2.2e-16 ***
year1992        5.6169e-01  6.1650e-02  9.1110 < 2.2e-16 ***
year1993        5.8056e-01  6.3715e-02  9.1119 < 2.2e-16 ***
year1994        5.6182e-01  6.6102e-02  8.4992 < 2.2e-16 ***
year1995        5.5165e-01  6.8703e-02  8.0294 9.793e-16 ***
year1996        4.9182e-01  7.1258e-02  6.9019 5.131e-12 ***
year1997        4.6551e-01  7.3527e-02  6.3312 2.433e-10 ***
year1998        4.0120e-01  7.5946e-02  5.2827 1.273e-07 ***
year1999        3.3662e-01  7.7740e-02  4.3300 1.491e-05 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Total Sum of Squares:    41.566
Residual Sum of Squares: 25.386
R-Squared:      0.38926
Adj. R-Squared: 0.37431
Chisq: 729.144 on 28 DF, p-value: < 2.22e-16

לאחר הסרת log_density הרצנו מחדש את מודלי Fixed Effects ו-Random Effects על אותו מפרט מצומצם.

ה- Standard Errors החריגים שנצפו קודם עבור משתני האוכלוסייה והצפיפות נעלמו, ולכן בעיית ה- multicollinearity טופלה.

מפרט משותף זה ישמש כעת לביצוע מבחן Hausman. בשלב זה איננו מבצעים עדיין סינון לפי מובהקות. סינון כזה יתבצע לאחר בחירת המודל.

Reduced Model Equation

לאחר הסרת log_density עקב ה- multicollinearity החזקה עם log_population בתוך המדינות, המשוואה ששימשה להשוואת מודלי FE ו-RE היא:

$$ \ln(violent_{it}) = \alpha + \beta_1 law_{it} + \beta_2 \ln(prisoners_{it}) + \beta_3 afam_{it} + \beta_4 male_{it} + \beta_5 \ln(population_{it}) + \beta_6 income_{it} + \sum_{t=1978}^{1999}\gamma_t D_t + u_{it} $$

9. Hausman Test and Model Selection

לאחר קביעת מפרט משותף וסופי לשני המודלים, נשתמש במבחן Hausman כדי לבחור בין Fixed Effects ל-Random Effects.

השערת האפס היא שמודל Random Effects מתאים, כלומר האפקטים הייחודיים של המדינות אינם מתואמים עם המשתנים המסבירים.

אם ערך ה- p-value קטן מ-0.05, נדחה את השערת האפס ונעדיף את מודל Fixed Effects. אחרת, נעדיף את מודל Random Effects.

Show code, cell 18
In [64]:
# Hausman test

hausman_test <- phtest(fe_reduced, re_reduced)

hausman_test
	Hausman Test

data:  formula_reduced
chisq = 38.504, df = 28, p-value = 0.08924
alternative hypothesis: one model is inconsistent

במבחן Hausman התקבל ערך p-value = 0.0892.

מכיוון שערך זה גדול מרמת המובהקות של 5%, איננו דוחים את השערת האפס של המבחן.

לכן אין עדות מספקת לכך שהאפקטים הייחודיים של המדינות מתואמים עם המשתנים המסבירים, ובהתאם נבחר במודל Random Effects כמודל המתאים להמשך הניתוח.

מכאן והלאה בדיקות השאריות ותיקוני המודל, במידת הצורך, יבוצעו על מודל Random Effects שנבחר.

10. Variable Selection in the Selected Model

לאחר שמבחן Hausman הוביל לבחירת מודל Random Effects, בחנו את מובהקות המשתנים המסבירים במודל הנבחר.

המשתנה log_prisoners לא נמצא מובהק, עם p-value = 0.672, ולכן הוסר מהמפרט.

המשתנים afam, male, log_population ו-income נמצאו מובהקים ברמת 5%.

המשתנה law התקבל עם p-value = 0.084. מושאר במכוון במפרט למרות מובהקות גבולית, משום שהוא מהווה את מוקד שאלת המחקר המרכזית, ובלעדיו המודל מאבד את משמעותו.

השארת המשתנה מאפשרת לבחון באופן ישיר האם קיומו של חוק Shall-Carry קשור לשיעור הפשיעה האלימה, גם אם בסופו של דבר ההשפעה אינה מובהקת ברמת 5%.

משתני השנה נשארים במודל כמשתני בקרה להשפעות משותפות לכל המדינות לאורך זמן.

הסינון יתבצע באופן הדרגתי: בכל שלב יוסר המסביר שאינו מובהק ובעל ערך ה- p-value הגבוה ביותר, ולאחר מכן המודל ייאמד מחדש.

Show code, cell 19
In [68]:
# Random Effects model after removing log_prisoners

formula_step1 <- log_violent ~
  law +
  afam +
  male +
  log_population +
  income +
  year

re_step1 <- plm(
  formula_step1,
  data = guns,
  index = c("state", "year"),
  model = "random"
)

summary(re_step1)
Oneway (individual) effect Random Effect Model 
   (Swamy-Arora's transformation)

Call:
plm(formula = formula_step1, data = guns, model = "random", index = c("state", 
    "year"))

Balanced Panel: n = 51, T = 23, N = 1173

Effects:
                  var std.dev share
idiosyncratic 0.01955 0.13983 0.092
individual    0.19363 0.44004 0.908
theta: 0.9339

Residuals:
      Min.    1st Qu.     Median    3rd Qu.       Max. 
-0.5096851 -0.0795459  0.0083383  0.0914193  0.6825377 

Coefficients:
                  Estimate  Std. Error z-value  Pr(>|z|)    
(Intercept)     4.1764e+00  2.3018e-01 18.1441 < 2.2e-16 ***
lawyes         -2.9182e-02  1.7429e-02 -1.6743   0.09407 .  
afam            1.5850e-02  8.4788e-03  1.8693   0.06158 .  
male            7.6384e-02  1.1219e-02  6.8082 9.882e-12 ***
log_population  6.1688e-02  4.5961e-02  1.3422   0.17954    
income          7.9234e-06  6.0593e-06  1.3076   0.19100    
year1978        5.5364e-02  2.8562e-02  1.9384   0.05258 .  
year1979        1.6138e-01  2.8729e-02  5.6171 1.942e-08 ***
year1980        2.1715e-01  2.8902e-02  7.5135 5.757e-14 ***
year1981        2.1692e-01  2.9319e-02  7.3985 1.378e-13 ***
year1982        1.9436e-01  3.0203e-02  6.4353 1.232e-10 ***
year1983        1.5604e-01  3.1579e-02  4.9412 7.765e-07 ***
year1984        1.8490e-01  3.3848e-02  5.4629 4.685e-08 ***
year1985        2.3302e-01  3.6258e-02  6.4267 1.304e-10 ***
year1986        3.0910e-01  3.9195e-02  7.8862 3.114e-15 ***
year1987        3.0704e-01  4.2125e-02  7.2888 3.128e-13 ***
year1988        3.6724e-01  4.5294e-02  8.1079 5.150e-16 ***
year1989        4.2055e-01  4.8250e-02  8.7161 < 2.2e-16 ***
year1990        5.3884e-01  5.0790e-02 10.6090 < 2.2e-16 ***
year1991        5.9342e-01  5.2998e-02 11.1972 < 2.2e-16 ***
year1992        6.2341e-01  5.5672e-02 11.1978 < 2.2e-16 ***
year1993        6.4557e-01  5.7445e-02 11.2380 < 2.2e-16 ***
year1994        6.3082e-01  5.9578e-02 10.5882 < 2.2e-16 ***
year1995        6.2420e-01  6.1568e-02 10.1383 < 2.2e-16 ***
year1996        5.6801e-01  6.3598e-02  8.9312 < 2.2e-16 ***
year1997        5.4577e-01  6.5510e-02  8.3311 < 2.2e-16 ***
year1998        4.8676e-01  6.7572e-02  7.2037 5.862e-13 ***
year1999        4.2619e-01  6.9064e-02  6.1709 6.791e-10 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Total Sum of Squares:    38.764
Residual Sum of Squares: 23.438
R-Squared:      0.39535
Adj. R-Squared: 0.38109
Chisq: 748.665 on 27 DF, p-value: < 2.22e-16

במודל המעודכן, income הוא המשתנה המסביר בעל ערך ה- p-value הגבוה ביותר (0.191).

לכן, במסגרת תהליך סינון המשתנים, נסיר בשלב הבא את income ונאמוד את המודל מחדש.

Show code, cell 20
In [71]:
# Random Effects model after removing income

formula_step2 <- log_violent ~
  law +
  afam +
  male +
  log_population +
  year

re_step2 <- plm(
  formula_step2,
  data = guns,
  index = c("state", "year"),
  model = "random"
)

summary(re_step2)
Oneway (individual) effect Random Effect Model 
   (Swamy-Arora's transformation)

Call:
plm(formula = formula_step2, data = guns, model = "random", index = c("state", 
    "year"))

Balanced Panel: n = 51, T = 23, N = 1173

Effects:
                  var std.dev share
idiosyncratic 0.01953 0.13976 0.089
individual    0.19935 0.44648 0.911
theta: 0.9349

Residuals:
      Min.    1st Qu.     Median    3rd Qu.       Max. 
-0.5096125 -0.0787621  0.0085484  0.0907753  0.6731014 

Coefficients:
                 Estimate Std. Error z-value  Pr(>|z|)    
(Intercept)     4.2593505  0.2223480 19.1562 < 2.2e-16 ***
lawyes         -0.0334290  0.0170894 -1.9561   0.05045 .  
afam            0.0154222  0.0085261  1.8088   0.07048 .  
male            0.0774355  0.0111911  6.9194 4.536e-12 ***
log_population  0.0553699  0.0462543  1.1971   0.23128    
year1978        0.0594290  0.0283792  2.0941   0.03625 *  
year1979        0.1652466  0.0285694  5.7841 7.292e-09 ***
year1980        0.2182705  0.0288755  7.5590 4.061e-14 ***
year1981        0.2188757  0.0292742  7.4767 7.619e-14 ***
year1982        0.1962709  0.0301627  6.5071 7.663e-11 ***
year1983        0.1601041  0.0314426  5.0919 3.544e-07 ***
year1984        0.1943250  0.0331445  5.8630 4.547e-09 ***
year1985        0.2453103  0.0351273  6.9835 2.880e-12 ***
year1986        0.3245277  0.0375227  8.6488 < 2.2e-16 ***
year1987        0.3248655  0.0400348  8.1146 4.875e-16 ***
year1988        0.3880270  0.0426308  9.1020 < 2.2e-16 ***
year1989        0.4440386  0.0450403  9.8587 < 2.2e-16 ***
year1990        0.5632244  0.0475168 11.8532 < 2.2e-16 ***
year1991        0.6171401  0.0500683 12.3260 < 2.2e-16 ***
year1992        0.6500455  0.0521302 12.4696 < 2.2e-16 ***
year1993        0.6728963  0.0538485 12.4961 < 2.2e-16 ***
year1994        0.6603045  0.0555254 11.8919 < 2.2e-16 ***
year1995        0.6555802  0.0571090 11.4795 < 2.2e-16 ***
year1996        0.6019005  0.0585278 10.2840 < 2.2e-16 ***
year1997        0.5829255  0.0595357  9.7912 < 2.2e-16 ***
year1998        0.5287042  0.0600695  8.8015 < 2.2e-16 ***
year1999        0.4709197  0.0606547  7.7639 8.233e-15 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Total Sum of Squares:    38.706
Residual Sum of Squares: 23.426
R-Squared:      0.39478
Adj. R-Squared: 0.38105
Chisq: 747.528 on 26 DF, p-value: < 2.22e-16

במודל המעודכן, log_population הוא המשתנה המסביר בעל ערך ה- p-value הגבוה ביותר (0.231), ולכן אינו מובהק ברמת 5%.

לעומתו, law נמצא קרוב מאוד לרמת מובהקות של 5%, afam מציג מובהקות חלשה ברמת 10%, ו-male מובהק מאוד.

לכן נסיר בשלב זה רק את log_population ונאמוד מחדש את המודל לפני קבלת החלטה נוספת.

Show code, cell 21
In [74]:
# Random Effects model after removing log_population

formula_step3 <- log_violent ~
  law +
  afam +
  male +
  year

re_step3 <- plm(
  formula_step3,
  data = guns,
  index = c("state", "year"),
  model = "random"
)

summary(re_step3)
Oneway (individual) effect Random Effect Model 
   (Swamy-Arora's transformation)

Call:
plm(formula = formula_step3, data = guns, model = "random", index = c("state", 
    "year"))

Balanced Panel: n = 51, T = 23, N = 1173

Effects:
                  var std.dev share
idiosyncratic 0.01966 0.14020 0.073
individual    0.24807 0.49806 0.927
theta: 0.9414

Residuals:
      Min.    1st Qu.     Median    3rd Qu.       Max. 
-0.5097268 -0.0782339  0.0091033  0.0893284  0.6665329 

Coefficients:
              Estimate Std. Error z-value  Pr(>|z|)    
(Intercept)  4.3247267  0.2159838 20.0234 < 2.2e-16 ***
lawyes      -0.0312279  0.0169162 -1.8460   0.06489 .  
afam         0.0131246  0.0087222  1.5047   0.13239    
male         0.0773923  0.0110933  6.9765 3.026e-12 ***
year1978     0.0602469  0.0281798  2.1379   0.03252 *  
year1979     0.1668951  0.0283629  5.8843 3.998e-09 ***
year1980     0.2207767  0.0286626  7.7026 1.333e-14 ***
year1981     0.2220089  0.0290500  7.6423 2.134e-14 ***
year1982     0.2000331  0.0299339  6.6825 2.349e-11 ***
year1983     0.1644677  0.0312096  5.2698 1.366e-07 ***
year1984     0.1992319  0.0329106  6.0537 1.415e-09 ***
year1985     0.2506967  0.0348942  7.1845 6.746e-13 ***
year1986     0.3302831  0.0372930  8.8564 < 2.2e-16 ***
year1987     0.3310094  0.0398078  8.3152 < 2.2e-16 ***
year1988     0.3946228  0.0424040  9.3063 < 2.2e-16 ***
year1989     0.4511548  0.0448120 10.0677 < 2.2e-16 ***
year1990     0.5708145  0.0472889 12.0708 < 2.2e-16 ***
year1991     0.6252803  0.0498337 12.5473 < 2.2e-16 ***
year1992     0.6588714  0.0518889 12.6977 < 2.2e-16 ***
year1993     0.6824688  0.0535971 12.7333 < 2.2e-16 ***
year1994     0.6705691  0.0552627 12.1342 < 2.2e-16 ***
year1995     0.6663261  0.0568400 11.7228 < 2.2e-16 ***
year1996     0.6130514  0.0582565 10.5233 < 2.2e-16 ***
year1997     0.5945494  0.0592617 10.0326 < 2.2e-16 ***
year1998     0.5408986  0.0597925  9.0463 < 2.2e-16 ***
year1999     0.4836876  0.0603751  8.0114 1.134e-15 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Total Sum of Squares:    38.34
Residual Sum of Squares: 23.121
R-Squared:      0.39696
Adj. R-Squared: 0.38381
Chisq: 755.025 on 25 DF, p-value: < 2.22e-16

המשתנה afam נותר לא מובהק, עם p-value = 0.132, ולכן יוסר מהמפרט.

המשתנה male נמצא מובהק מאוד, ואילו law מציג מובהקות חלשה ברמת 10% ונשאר במודל בשל תפקידו כמשתנה המדיניות המרכזי של הניתוח.

Show code, cell 22
In [77]:
# Final Random Effects model

formula_final <- log_violent ~
  law +
  male +
  year

re_final <- plm(
  formula_final,
  data = guns,
  index = c("state", "year"),
  model = "random"
)

summary(re_final)
Oneway (individual) effect Random Effect Model 
   (Swamy-Arora's transformation)

Call:
plm(formula = formula_final, data = guns, model = "random", index = c("state", 
    "year"))

Balanced Panel: n = 51, T = 23, N = 1173

Effects:
                  var std.dev share
idiosyncratic 0.01967 0.14024 0.061
individual    0.30480 0.55208 0.939
theta: 0.9471

Residuals:
      Min.    1st Qu.     Median    3rd Qu.       Max. 
-0.5085534 -0.0755914  0.0095222  0.0886114  0.6611378 

Coefficients:
             Estimate Std. Error z-value  Pr(>|z|)    
(Intercept)  4.334922   0.217348 19.9446 < 2.2e-16 ***
lawyes      -0.032118   0.016791 -1.9128   0.05577 .  
male         0.080238   0.010908  7.3555 1.902e-13 ***
year1978     0.061330   0.028009  2.1896   0.02855 *  
year1979     0.169082   0.028166  6.0031 1.936e-09 ***
year1980     0.224541   0.028397  7.9073 2.630e-15 ***
year1981     0.226542   0.028739  7.8826 3.206e-15 ***
year1982     0.205911   0.029528  6.9734 3.094e-12 ***
year1983     0.171634   0.030700  5.5906 2.262e-08 ***
year1984     0.207784   0.032279  6.4371 1.218e-10 ***
year1985     0.260635   0.034134  7.6357 2.246e-14 ***
year1986     0.341700   0.036386  9.3911 < 2.2e-16 ***
year1987     0.343970   0.038742  8.8786 < 2.2e-16 ***
year1988     0.409172   0.041168  9.9391 < 2.2e-16 ***
year1989     0.467230   0.043407 10.7639 < 2.2e-16 ***
year1990     0.588551   0.045682 12.8837 < 2.2e-16 ***
year1991     0.644396   0.048068 13.4058 < 2.2e-16 ***
year1992     0.679366   0.049949 13.6011 < 2.2e-16 ***
year1993     0.704120   0.051514 13.6685 < 2.2e-16 ***
year1994     0.693267   0.053052 13.0676 < 2.2e-16 ***
year1995     0.690072   0.054484 12.6656 < 2.2e-16 ***
year1996     0.637885   0.055736 11.4448 < 2.2e-16 ***
year1997     0.620397   0.056577 10.9656 < 2.2e-16 ***
year1998     0.567713   0.056939  9.9705 < 2.2e-16 ***
year1999     0.511512   0.057342  8.9203 < 2.2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Total Sum of Squares:    38.053
Residual Sum of Squares: 22.875
R-Squared:      0.39885
Adj. R-Squared: 0.38629
Chisq: 761.684 on 24 DF, p-value: < 2.22e-16

לאחר תהליך סינון המשתנים התקבל המודל הסופי.

המשתנה male נמצא מובהק מאוד (p-value < 0.001).

המשתנה law התקבל עם p-value = 0.056. לכן הוא אינו מובהק ברמת 5%, אך מציג מובהקות חלשה ברמת 10%. המשתנה נשמר במודל בשל תפקידו כמשתנה המדיניות המרכזי של הניתוח.

משתני השנה נמצאו ברובם המכריע מובהקים מאוד ונשמרו במודל כדי לשלוט בשינויים המשותפים לכל המדינות לאורך זמן.

למודל הסופי התקבל R² = 0.399.

מאחר שבשלב זה טרם נבדק מבנה השגיאה, המסקנות הסופיות לגבי מובהקות המקדמים ייקבעו לאחר ביצוע בדיקות השאריות והתיקון המתאים במידת הצורך.

מודל זה ייחשב למודל Random Effects הסופי, ועליו נבצע את בדיקות השגיאה.

Final Model Equation

לאחר בחירת מודל Random Effects וסיום תהליך סינון המשתנים, המפרט הסופי הוא:

$$ \ln(violent_{it}) = \alpha + \beta_1 law_{it} + \beta_2 male_{it} + \sum_{t=1978}^{1999}\gamma_t D_t + \mu_i + \varepsilon_{it} $$

במשוואה הסופית:

  • $law_{it}$ מציין האם חוק Shall-Carry היה בתוקף במדינה ובשנה הנתונות.
  • $male_{it}$ הוא אחוז הגברים בגילאי 10–29.
  • $\gamma_t$ מייצגים השפעות שנה ביחס לשנת הבסיס 1977.
  • $\mu_i$ הוא האפקט האקראי הייחודי למדינה.
  • $\varepsilon_{it}$ הוא רכיב השגיאה המשתנה בין מדינה ושנה.

מודל זה הוא המודל שעליו יבוצעו בדיקות השאריות וה- misspecification.

11. Residual Diagnostics

לאחר קביעת מודל Random Effects הסופי, נבחן את שאריות המודל כדי לבדוק האם קיימות בעיות במבנה השגיאה.

נבחן תחילה את פיזור השאריות ביחס לערכים החזויים. לאחר מכן נבדוק heteroskedasticity ואת נורמליות השאריות.

Show code, cell 23
In [82]:
# Residuals vs Fitted - final Random Effects model

res_final <- as.numeric(resid(re_final))
fit_final <- as.numeric(fitted(re_final))

options(repr.plot.width = 12, repr.plot.height = 7)

plot(
  fit_final,
  res_final,
  main = "Residuals vs Fitted - Final Random Effects Model",
  xlab = "Fitted Values",
  ylab = "Residuals",
  pch = 20
)

abline(h = 0, col = "red")
No description has been provided for this image

גרף Residuals vs Fitted מראה כי השאריות מפוזרות באופן כללי סביב אפס, ללא מגמה או תבנית לא-ליניארית ברורה.

עם זאת, מידת הפיזור של השאריות אינה נראית אחידה לחלוטין לאורך כל טווח הערכים החזויים.

לכן לא ניתן להסיק מהגרף בלבד כי שונות השגיאה קבועה, ונבצע מבחן פורמלי ל- heteroskedasticity.

Heteroskedasticity Test

נשתמש במבחן Breusch–Pagan כדי לבדוק האם שונות השגיאות קבועה.

השערת האפס היא כי קיימת שונות קבועה בשגיאות:

$$ H_0:\ Var(\varepsilon_{it})=\sigma^2 $$

לעומת ההשערה החלופית שלפיה שונות השגיאות אינה קבועה.

אם ערך ה- p-value קטן מ-0.05, נדחה את השערת האפס ונקבע שקיימת עדות ל- heteroskedasticity.

Show code, cell 24
In [86]:
# Breusch-Pagan heteroskedasticity test

hetero_test <- bptest(
  re_final,
  varformula = ~ fitted(re_final) + I(fitted(re_final)^2),
  studentize = FALSE
)

hetero_test
	Breusch-Pagan test

data:  re_final
BP = 8.956, df = 2, p-value = 0.01136

במבחן Breusch–Pagan התקבל p-value = 0.0114.

מכיוון שערך זה קטן מרמת המובהקות של 5%, אנו דוחים את השערת האפס של שונות קבועה בשגיאות.

לכן קיימת עדות סטטיסטית ל- heteroskedasticity בשאריות מודל Random Effects הסופי.

ממצא זה מצביע על misspecification במבנה השגיאה, ולכן לאחר השלמת בדיקות השאריות ננסה לתקן את המודל.

Normality of Residuals

בנוסף לבדיקת שונות השגיאות, נבחן האם שאריות המודל מתפלגות בקירוב נורמלית.

הבדיקה תתבצע באופן גרפי באמצעות Q-Q Plot והיסטוגרמת השאריות, ובאופן פורמלי באמצעות מבחן Jarque–Bera.

במבחן JB השערת האפס היא שהשאריות מתפלגות נורמלית:

$$ H_0:\ \varepsilon_{it}\sim N(0,\sigma^2) $$
Show code, cell 25
In [90]:
# Normality diagnostics - final Random Effects model

options(repr.plot.width = 14, repr.plot.height = 6)

par(mfrow = c(1, 2))

# Q-Q plot
qqnorm(
  res_final,
  main = "Q-Q Plot - Final Random Effects Residuals"
)
qqline(res_final, col = "red")

# Histogram
hist(
  res_final,
  breaks = 30,
  freq = FALSE,
  main = "Histogram - Final Random Effects Residuals",
  xlab = "Residuals"
)

lines(density(res_final), lwd = 2)

curve(
  dnorm(
    x,
    mean = mean(res_final),
    sd = sd(res_final)
  ),
  col = "red",
  lwd = 2,
  add = TRUE
)

par(mfrow = c(1, 1))
No description has been provided for this image
Show code, cell 26
In [92]:
# Jarque-Bera normality test

jb_test <- jarque.bera.test(res_final)

jb_test
	Jarque Bera Test

data:  res_final
X-squared = 45.233, df = 2, p-value = 1.506e-10

גרף Q-Q מראה כי מרבית השאריות במרכז ההתפלגות נמצאות קרוב לקו התאורטי, אך קיימות סטיות ברורות בזנבות.

גם ההיסטוגרמה מצביעה על התפלגות דמוית נורמלית במרכז, אך עם זנבות שאינם מתאימים באופן מלא להתפלגות נורמלית.

במבחן Jarque–Bera התקבל p-value = 1.506×10⁻¹⁰, ולכן אנו דוחים את השערת האפס של נורמליות השאריות.

בשילוב עם תוצאת מבחן Breusch–Pagan, המסקנה היא כי במודל הסופי קיימת heteroskedasticity וכן סטייה מנורמליות השאריות.

ננסה כעת לתקן את בעיית מבנה השגיאה.

12. Model Correction

בדיקות השאריות הצביעו על heteroskedasticity ועל סטייה מנורמליות.

מודל Random Effects שנבחר באמצעות מבחן Hausman נשאר מודל הפאנל המרכזי של הניתוח.

תחילה נתקן את ההסקה הסטטיסטית באמצעות robust standard errors, אשר שומרים על אומדי מודל RE אך מתקנים את אומדני אי-הוודאות תחת שונות לא קבועה.

לאחר מכן נבצע גם ניסיון FGLS כדי לבחון האם ניתן לתקן את מבנה השגיאה עצמו.

12.1 Robust Standard Errors

Show code, cell 27
In [96]:
# Robust standard errors for the final Random Effects model

re_final_robust <- coeftest(
  re_final,
  vcov = vcovHC(
    re_final,
    method = "arellano",
    type = "HC1",
    cluster = "group"
  )
)

re_final_robust
t test of coefficients:

              Estimate Std. Error t value  Pr(>|t|)    
(Intercept)  4.3349222  0.5830729  7.4346 2.045e-13 ***
lawyes      -0.0321184  0.0422381 -0.7604 0.4471648    
male         0.0802377  0.0303041  2.6478 0.0082139 ** 
year1978     0.0613298  0.0096669  6.3443 3.208e-10 ***
year1979     0.1690820  0.0159301 10.6140 < 2.2e-16 ***
year1980     0.2245409  0.0245378  9.1508 < 2.2e-16 ***
year1981     0.2265415  0.0271251  8.3517 < 2.2e-16 ***
year1982     0.2059107  0.0300233  6.8584 1.136e-11 ***
year1983     0.1716341  0.0366084  4.6884 3.084e-06 ***
year1984     0.2077843  0.0461139  4.5059 7.285e-06 ***
year1985     0.2606345  0.0554420  4.7010 2.902e-06 ***
year1986     0.3417005  0.0670379  5.0971 4.030e-07 ***
year1987     0.3439705  0.0782419  4.3962 1.203e-05 ***
year1988     0.4091720  0.0846881  4.8315 1.538e-06 ***
year1989     0.4672302  0.0926647  5.0422 5.345e-07 ***
year1990     0.5885509  0.1015500  5.7957 8.783e-09 ***
year1991     0.6443963  0.1077927  5.9781 3.010e-09 ***
year1992     0.6793664  0.1149000  5.9127 4.435e-09 ***
year1993     0.7041200  0.1185816  5.9379 3.822e-09 ***
year1994     0.6932673  0.1231682  5.6286 2.282e-08 ***
year1995     0.6900723  0.1247237  5.5328 3.902e-08 ***
year1996     0.6378846  0.1293843  4.9302 9.425e-07 ***
year1997     0.6203970  0.1317615  4.7085 2.800e-06 ***
year1998     0.5677129  0.1343710  4.2250 2.579e-05 ***
year1999     0.5115120  0.1398877  3.6566 0.0002672 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

התיקון אינו משנה את אומדי המקדמים, אלא מתקן את אומדני Standard Errors ואת מבחני המובהקות שלהם.

חישוב מטריצת השונות בוצע בשיטת Arellano HC1 עם קיבוץ לפי מדינה (cluster = "group"). כך ההסקה עמידה להטרוסקדסטיות ולתלות אפשרית בין תצפיות החוזרות של אותה מדינה לאורך זמן.

לאחר התיקון, המשתנה male נותר מובהק ברמת 1% (p-value = 0.0082).

לעומת זאת, המשתנה law אינו מובהק לאחר התיקון (p-value = 0.447).

לכן, לאחר התחשבות ב- heteroskedasticity, אין עדות סטטיסטית מספקת לכך שקיומו של חוק Shall-Carry קשור לשיעור הפשיעה האלימה, כאשר יתר המשתנים וההשפעות השנתיות מוחזקים קבועים.

12.2 FGLS Correction Attempt

בנוסף לתיקון השגיאות החסינות, ננסה לתקן את heteroskedasticity באמצעות FGLS.

בשלב הראשון נאמוד את שונות השגיאות באמצעות רגרסיה של ריבועי השאריות על המשתנים המסבירים. השונויות החזויות ישמשו ליצירת משקולות עבור מודל GLS.

לאחר מכן נבצע את התהליך באופן איטרטיבי: בכל איטרציה יחושבו שאריות חדשות, יאומד מחדש מודל השונות וייאמד מודל GLS חדש. התהליך ייעצר כאשר השינוי בערכים החזויים יהיה קטן מסף ההתכנסות.

מפרט הממוצע שנשמר הוא:

$$ \ln(violent_{it}) = \alpha + \beta_1 law_{it} + \beta_2 male_{it} + \sum_{t=1978}^{1999}\gamma_tD_t + \varepsilon_{it} $$

חשוב להדגיש כי nlme::gls אינו משחזר את מבנה ה- Random Effects של plm. לכן ה- FGLS ישמש כניסיון לתיקון מבנה השגיאה וכבדיקת עמידות, ולא כתחליף למודל RE שנבחר באמצעות Hausman.

Show code, cell 28
In [100]:
# Initial variance estimation for FGLS

fgls_residuals <- as.numeric(resid(re_final))

variance_model <- lm(
  I(fgls_residuals^2) ~ law + male + year,
  data = guns
)

fitted_variances <- fitted(variance_model)

# Initial FGLS model

fgls_model <- gls(
  formula_final,
  data = guns,
  weights = varFixed(~ fitted_variances)
)

summary(fgls_model)
Generalized least squares fit by REML
  Model: formula_final 
  Data: guns 
       AIC      BIC    logLik
  2248.032 2379.223 -1098.016

Variance function:
 Structure: fixed weights
 Formula: ~fitted_variances 

Coefficients:
                Value Std.Error    t-value p-value
(Intercept)  5.931822 0.4064717  14.593444  0.0000
lawyes      -0.628887 0.0500516 -12.564767  0.0000
male        -0.003643 0.0211824  -0.171972  0.8635
year1978     0.046825 0.1383969   0.338336  0.7352
year1979     0.139941 0.1293884   1.081560  0.2797
year1980     0.181533 0.1389156   1.306790  0.1915
year1981     0.177911 0.1420667   1.252308  0.2107
year1982     0.152397 0.1278534   1.191967  0.2335
year1983     0.092945 0.1251154   0.742871  0.4577
year1984     0.100422 0.1239255   0.810342  0.4179
year1985     0.125864 0.1256725   1.001525  0.3168
year1986     0.231324 0.1294442   1.787056  0.0742
year1987     0.221733 0.1304105   1.700272  0.0894
year1988     0.261529 0.1358457   1.925191  0.0545
year1989     0.297933 0.1382404   2.155178  0.0314
year1990     0.429961 0.1396670   3.078471  0.0021
year1991     0.497186 0.1523046   3.264415  0.0011
year1992     0.535944 0.1527217   3.509282  0.0005
year1993     0.543909 0.1528279   3.558964  0.0004
year1994     0.514605 0.1590078   3.236354  0.0012
year1995     0.536088 0.1601129   3.348190  0.0008
year1996     0.523635 0.1648043   3.177315  0.0015
year1997     0.536736 0.1718868   3.122614  0.0018
year1998     0.483226 0.1737865   2.780570  0.0055
year1999     0.425891 0.1832276   2.324384  0.0203

 Correlation: 
         (Intr) lawyes male   yr1978 yr1979 yr1980 yr1981 yr1982 yr1983 yr1984
lawyes    0.063                                                               
male     -0.970 -0.072                                                        
year1978 -0.200 -0.001  0.024                                                 
year1979 -0.234 -0.001  0.047  0.554                                          
year1980 -0.244 -0.005  0.071  0.517  0.554                                   
year1981 -0.263 -0.007  0.094  0.506  0.543  0.508                            
year1982 -0.329 -0.012  0.143  0.563  0.605  0.568  0.559                     
year1983 -0.384 -0.014  0.195  0.577  0.621  0.584  0.576  0.647              
year1984 -0.439 -0.017  0.250  0.583  0.629  0.593  0.586  0.661  0.687       
year1985 -0.485 -0.021  0.301  0.577  0.623  0.589  0.583  0.659  0.688  0.711
year1986 -0.524 -0.035  0.347  0.561  0.607  0.575  0.571  0.648  0.679  0.704
year1987 -0.572 -0.042  0.397  0.558  0.605  0.575  0.572  0.651  0.684  0.712
year1988 -0.595 -0.051  0.429  0.537  0.583  0.555  0.554  0.631  0.666  0.695
year1989 -0.625 -0.053  0.463  0.529  0.575  0.549  0.548  0.626  0.663  0.694
year1990 -0.653 -0.067  0.493  0.524  0.571  0.545  0.546  0.625  0.663  0.695
year1991 -0.637 -0.088  0.493  0.482  0.525  0.503  0.504  0.579  0.616  0.648
year1992 -0.662 -0.099  0.519  0.481  0.525  0.504  0.505  0.581  0.619  0.653
year1993 -0.685 -0.100  0.542  0.481  0.526  0.505  0.507  0.584  0.624  0.658
year1994 -0.681 -0.102  0.545  0.463  0.507  0.487  0.490  0.565  0.604  0.639
year1995 -0.695 -0.124  0.560  0.460  0.504  0.485  0.488  0.564  0.604  0.639
year1996 -0.687 -0.151  0.557  0.448  0.490  0.472  0.476  0.550  0.589  0.624
year1997 -0.668 -0.167  0.543  0.429  0.470  0.453  0.457  0.528  0.566  0.601
year1998 -0.665 -0.167  0.542  0.425  0.465  0.449  0.452  0.523  0.561  0.595
year1999 -0.635 -0.162  0.519  0.403  0.442  0.426  0.430  0.497  0.533  0.566
         yr1985 yr1986 yr1987 yr1988 yr1989 yr1990 yr1991 yr1992 yr1993 yr1994
lawyes                                                                        
male                                                                          
year1978                                                                      
year1979                                                                      
year1980                                                                      
year1981                                                                      
year1982                                                                      
year1983                                                                      
year1984                                                                      
year1985                                                                      
year1986  0.713                                                               
year1987  0.724  0.724                                                        
year1988  0.709  0.712  0.729                                                 
year1989  0.709  0.714  0.733  0.726                                          
year1990  0.712  0.719  0.740  0.734  0.742                                   
year1991  0.665  0.674  0.695  0.691  0.699  0.710                            
year1992  0.672  0.681  0.704  0.701  0.710  0.722  0.685                     
year1993  0.679  0.689  0.713  0.711  0.721  0.733  0.696  0.709              
year1994  0.659  0.671  0.695  0.693  0.704  0.717  0.681  0.694  0.707       
year1995  0.660  0.673  0.698  0.697  0.708  0.722  0.687  0.701  0.714  0.699
year1996  0.645  0.658  0.683  0.683  0.694  0.708  0.675  0.689  0.702  0.688
year1997  0.622  0.635  0.659  0.660  0.671  0.685  0.653  0.667  0.679  0.666
year1998  0.616  0.629  0.654  0.654  0.665  0.680  0.648  0.662  0.675  0.662
year1999  0.586  0.599  0.622  0.623  0.634  0.647  0.617  0.631  0.643  0.631
         yr1995 yr1996 yr1997 yr1998
lawyes                              
male                                
year1978                            
year1979                            
year1980                            
year1981                            
year1982                            
year1983                            
year1984                            
year1985                            
year1986                            
year1987                            
year1988                            
year1989                            
year1990                            
year1991                            
year1992                            
year1993                            
year1994                            
year1995                            
year1996  0.696                     
year1997  0.675  0.666              
year1998  0.670  0.662  0.642       
year1999  0.639  0.631  0.613  0.608

Standardized residuals:
        Min          Q1         Med          Q3         Max 
-4.85061172 -0.68650114  0.08388317  0.64867876  3.16665748 

Residual standard error: 4.462034 
Degrees of freedom: 1173 total; 1148 residual
Show code, cell 29
In [102]:
# Iterate FGLS until convergence

tolerance <- 1e-6
max_iterations <- 10
iteration <- 1
converged <- FALSE

while (iteration <= max_iterations & !converged) {

  # Update residuals
  fgls_residuals <- residuals(fgls_model)

  # Re-estimate the variance model
  variance_model <- lm(
    I(fgls_residuals^2) ~ law + male + year,
    data = guns
  )

  new_fitted_variances <- fitted(variance_model)

  # Re-estimate FGLS with updated variance estimates
  new_fgls_model <- gls(
    formula_final,
    data = guns,
    weights = varFixed(~ new_fitted_variances)
  )

  # Check convergence
  if (sum((fitted(new_fgls_model) - fitted(fgls_model))^2) < tolerance) {
    converged <- TRUE
  }

  # Update
  fgls_model <- new_fgls_model
  fitted_variances <- new_fitted_variances
  iteration <- iteration + 1
}

cat("FGLS converged:", converged, "\n")
cat("Iterations:", iteration - 1, "\n")

summary(fgls_model)
FGLS converged: TRUE 
Iterations: 4 
Generalized least squares fit by REML
  Model: formula_final 
  Data: guns 
       AIC      BIC    logLik
  2186.015 2317.206 -1067.008

Variance function:
 Structure: fixed weights
 Formula: ~new_fitted_variances 

Coefficients:
                Value Std.Error    t-value p-value
(Intercept)  5.951096 0.3662082  16.250579  0.0000
lawyes      -0.572184 0.0494083 -11.580718  0.0000
male        -0.004863 0.0190158  -0.255711  0.7982
year1978     0.043754 0.1055869   0.414391  0.6787
year1979     0.138793 0.1072453   1.294161  0.1959
year1980     0.172222 0.1119700   1.538105  0.1243
year1981     0.176699 0.1141802   1.547545  0.1220
year1982     0.152302 0.1141714   1.333979  0.1825
year1983     0.092030 0.1136883   0.809498  0.4184
year1984     0.098869 0.1136004   0.870326  0.3843
year1985     0.123706 0.1167834   1.059273  0.2897
year1986     0.232995 0.1149612   2.026731  0.0429
year1987     0.222274 0.1168760   1.901796  0.0574
year1988     0.259369 0.1245074   2.083163  0.0375
year1989     0.295060 0.1274664   2.314809  0.0208
year1990     0.423358 0.1288597   3.285416  0.0010
year1991     0.493524 0.1329387   3.712418  0.0002
year1992     0.527487 0.1332092   3.959842  0.0001
year1993     0.532652 0.1351680   3.940663  0.0001
year1994     0.500777 0.1369612   3.656343  0.0003
year1995     0.511079 0.1394336   3.665394  0.0003
year1996     0.483604 0.1426299   3.390619  0.0007
year1997     0.482170 0.1438557   3.351759  0.0008
year1998     0.426869 0.1425262   2.995023  0.0028
year1999     0.358937 0.1424469   2.519797  0.0119

 Correlation: 
         (Intr) lawyes male   yr1978 yr1979 yr1980 yr1981 yr1982 yr1983 yr1984
lawyes    0.097                                                               
male     -0.979 -0.105                                                        
year1978 -0.178 -0.004  0.037                                                 
year1979 -0.207 -0.008  0.069  0.485                                          
year1980 -0.236 -0.013  0.104  0.466  0.463                                   
year1981 -0.263 -0.017  0.135  0.459  0.456  0.442                            
year1982 -0.308 -0.027  0.181  0.460  0.459  0.447  0.444                     
year1983 -0.359 -0.031  0.233  0.464  0.464  0.454  0.453  0.463              
year1984 -0.412 -0.036  0.286  0.467  0.469  0.460  0.460  0.473  0.490       
year1985 -0.453 -0.042  0.332  0.456  0.459  0.453  0.455  0.470  0.489  0.507
year1986 -0.511 -0.056  0.389  0.465  0.470  0.465  0.469  0.487  0.509  0.530
year1987 -0.555 -0.066  0.437  0.459  0.466  0.463  0.469  0.489  0.513  0.537
year1988 -0.569 -0.074  0.458  0.433  0.441  0.440  0.447  0.468  0.493  0.518
year1989 -0.595 -0.077  0.488  0.424  0.434  0.434  0.442  0.464  0.491  0.517
year1990 -0.623 -0.093  0.518  0.421  0.431  0.433  0.442  0.466  0.494  0.522
year1991 -0.641 -0.111  0.541  0.410  0.421  0.424  0.433  0.458  0.488  0.517
year1992 -0.668 -0.123  0.567  0.410  0.422  0.426  0.436  0.463  0.493  0.524
year1993 -0.683 -0.124  0.584  0.405  0.418  0.422  0.434  0.460  0.492  0.524
year1994 -0.697 -0.126  0.600  0.401  0.414  0.419  0.431  0.459  0.491  0.524
year1995 -0.706 -0.149  0.612  0.394  0.408  0.414  0.426  0.455  0.488  0.521
year1996 -0.704 -0.177  0.612  0.386  0.400  0.407  0.419  0.447  0.480  0.513
year1997 -0.709 -0.196  0.618  0.383  0.397  0.404  0.417  0.446  0.479  0.512
year1998 -0.719 -0.195  0.628  0.387  0.401  0.409  0.421  0.451  0.484  0.518
year1999 -0.724 -0.195  0.633  0.387  0.402  0.409  0.422  0.452  0.486  0.520
         yr1985 yr1986 yr1987 yr1988 yr1989 yr1990 yr1991 yr1992 yr1993 yr1994
lawyes                                                                        
male                                                                          
year1978                                                                      
year1979                                                                      
year1980                                                                      
year1981                                                                      
year1982                                                                      
year1983                                                                      
year1984                                                                      
year1985                                                                      
year1986  0.536                                                               
year1987  0.546  0.577                                                        
year1988  0.528  0.561  0.576                                                 
year1989  0.529  0.563  0.581  0.569                                          
year1990  0.535  0.571  0.590  0.579  0.586                                   
year1991  0.532  0.569  0.589  0.579  0.588  0.601                            
year1992  0.540  0.579  0.600  0.591  0.601  0.615  0.619                     
year1993  0.541  0.580  0.603  0.594  0.604  0.619  0.624  0.639              
year1994  0.541  0.582  0.605  0.597  0.608  0.623  0.628  0.644  0.650       
year1995  0.539  0.581  0.605  0.598  0.609  0.625  0.631  0.647  0.653  0.659
year1996  0.532  0.573  0.598  0.591  0.602  0.619  0.625  0.642  0.649  0.655
year1997  0.531  0.573  0.598  0.592  0.603  0.620  0.627  0.645  0.651  0.657
year1998  0.538  0.580  0.605  0.599  0.611  0.628  0.635  0.653  0.659  0.665
year1999  0.539  0.582  0.608  0.602  0.613  0.631  0.638  0.656  0.662  0.668
         yr1995 yr1996 yr1997 yr1998
lawyes                              
male                                
year1978                            
year1979                            
year1980                            
year1981                            
year1982                            
year1983                            
year1984                            
year1985                            
year1986                            
year1987                            
year1988                            
year1989                            
year1990                            
year1991                            
year1992                            
year1993                            
year1994                            
year1995                            
year1996  0.659                     
year1997  0.662  0.660              
year1998  0.671  0.668  0.672       
year1999  0.674  0.671  0.675  0.684

Standardized residuals:
       Min         Q1        Med         Q3        Max 
-3.9883730 -0.7385098  0.1140182  0.6886200  2.8138803 

Residual standard error: 1.011053 
Degrees of freedom: 1173 total; 1148 residual
Show code, cell 30
In [104]:
# Check the estimated variance function

range(new_fitted_variances)
sum(new_fitted_variances <= 0)
  1. 0.0766755000180978
  2. 0.652228567954739
0

אומדני השונות שהתקבלו ממודל השונות נמצאים בטווח 0.077–0.652, ולא התקבלו אומדני שונות שליליים.

לכן פונקציית השונות ששימשה ליצירת המשקולות ב- FGLS תקינה מבחינה בסיסית, וניתן להמשיך ולבדוק האם האמידה המשוקללת אכן שיפרה את התנהגות השאריות.

12.3 FGLS Residual Diagnostics

כדי לבדוק האם תיקון FGLS הצליח לצמצם את ה- heteroskedasticity, נבחן מחדש את השאריות לאחר האמידה המשוקללת.

נשתמש בשאריות המנורמלות של מודל FGLS, ונבצע מחדש את גרף Residuals vs Fitted ואת מבחן Breusch–Pagan.

Show code, cell 31
In [108]:
# FGLS residual diagnostics

res_fgls <- as.numeric(residuals(fgls_model, type = "normalized"))
fit_fgls <- as.numeric(fitted(fgls_model))

options(repr.plot.width = 12, repr.plot.height = 7)

plot(
  fit_fgls,
  res_fgls,
  main = "Residuals vs Fitted - FGLS Model",
  xlab = "Fitted Values",
  ylab = "Normalized Residuals",
  pch = 20
)

abline(h = 0, col = "red")
No description has been provided for this image
Show code, cell 32
In [110]:
# Breusch-Pagan test after FGLS

hetero_test_fgls <- bptest(
  res_fgls ~ fit_fgls + I(fit_fgls^2),
  studentize = FALSE
)

hetero_test_fgls
	Breusch-Pagan test

data:  res_fgls ~ fit_fgls + I(fit_fgls^2)
BP = 10.722, df = 2, p-value = 0.004695

מודל FGLS התכנס לאחר 4 איטרציות, אך בדיקת השאריות מראה כי תיקון ההטרוסקדסטיות לא הצליח.

במבחן Breusch–Pagan לאחר FGLS התקבל p-value = 0.0047.

מכיוון שערך זה קטן מ-0.05, אנו עדיין דוחים את השערת האפס של שונות קבועה בשגיאות.

לכן, למרות שהאלגוריתם התכנס והמשקולות התבססו על אומדני שונות חיוביים, מודל FGLS לא הצליח להסיר את ה- heteroskedasticity מהשאריות.

בהתאם לכך, תוצאות מודל Random Effects עם robust standard errors יישארו הבסיס המרכזי להסקה הסטטיסטית, בעוד שה- FGLS יוצג כניסיון נוסף לתיקון מבנה השגיאה שלא פתר את הבעיה במלואה.

12.4 Normality after FGLS

נבחן גם האם אמידת FGLS שיפרה את נורמליות השאריות באמצעות Q-Q Plot, היסטוגרמה ומבחן Jarque–Bera.

Show code, cell 33
In [114]:
# Normality diagnostics after FGLS

options(repr.plot.width = 14, repr.plot.height = 6)

par(mfrow = c(1, 2))

qqnorm(
  res_fgls,
  main = "Q-Q Plot - FGLS Residuals"
)
qqline(res_fgls, col = "red")

hist(
  res_fgls,
  breaks = 30,
  freq = FALSE,
  main = "Histogram - FGLS Residuals",
  xlab = "Normalized Residuals"
)

lines(density(res_fgls), lwd = 2)

curve(
  dnorm(
    x,
    mean = mean(res_fgls),
    sd = sd(res_fgls)
  ),
  col = "red",
  lwd = 2,
  add = TRUE
)

par(mfrow = c(1, 1))
No description has been provided for this image
Show code, cell 34
In [116]:
# Jarque-Bera test after FGLS

jb_test_fgls <- jarque.bera.test(res_fgls)

jb_test_fgls
	Jarque Bera Test

data:  res_fgls
X-squared = 44.837, df = 2, p-value = 1.836e-10

גם לאחר אמידת FGLS מבחן Jarque–Bera דוחה את השערת הנורמליות, עם p-value = 1.836×10⁻¹⁰.

גם מבחינה גרפית, גרף Q-Q מצביע על התאמה סבירה יחסית במרכז ההתפלגות, אך על סטיות ברורות בזנבות.

בנוסף, מבחן Breusch–Pagan שבוצע לאחר FGLS התקבל עם p-value = 0.0047, ולכן גם בעיית ה- heteroskedasticity לא נפתרה.

לפיכך, אף שמודל FGLS התכנס לאחר ארבע איטרציות והשתמש באומדני שונות חיוביים, ניסיון התיקון לא הצליח להביא לקיום מלא של הנחות השגיאה.

בהתאם לכך, מודל Random Effects נשאר המודל המרכזי של הניתוח, וההסקה הסטטיסטית ממנו תתבסס על robust standard errors כדי להתמודד עם ההטרוסקדסטיות.

13. Final Results and Conclusions

בשלב הראשון נאמדו מודלי Fixed Effects ו-Random Effects על אותו מפרט.

לאחר טיפול ב- multicollinearity בין log_population ו-log_density, בוצע מבחן Hausman. במבחן התקבל p-value = 0.0892, ולכן ברמת מובהקות של 5% לא דחינו את השערת האפס ובחרנו במודל Random Effects.

לאחר בחירת המודל בוצע סינון הדרגתי של המשתנים המסבירים. המודל הסופי שהתקבל הוא:

$$ \ln(violent_{it}) = \alpha + \beta_1 law_{it} + \beta_2 male_{it} + \sum_{t=1978}^{1999}\gamma_tD_t + \mu_i + \varepsilon_{it} $$

במודל Random Effects הסופי התקבל עבור law מקדם של -0.0321.

אומדן נקודתי זה מתאים בקירוב לירידה של כ-3.16% בשיעור הפשיעה האלימה כאשר חוק Shall-Carry בתוקף.

עם זאת, לאחר שנמצאה heteroskedasticity וחושבו robust standard errors, התקבל עבור law ערך p-value = 0.447.

לכן אין עדות סטטיסטית מספקת לכך שקיומו של חוק Shall-Carry קשור לשינוי בשיעור הפשיעה האלימה. כלומר, אין לפרש את הירידה הנקודתית של כ-3.16% כהשפעה מובהקת.

עבור male התקבל מקדם של 0.0802, והמשתנה נשאר מובהק גם לאחר תיקון השגיאות (p-value = 0.0082).

מכיוון שהמשתנה המוסבר נמצא בסקאלה לוגריתמית, עלייה של נקודת אחוז אחת ב- male קשורה בקירוב לעלייה של כ-8% בשיעור הפשיעה האלימה, בהינתן יתר המשתנים במודל.

גם משתני השנה מצביעים על שינויים משמעותיים בשיעור הפשיעה האלימה לאורך תקופת המדגם ביחס לשנת הבסיס 1977.

למודל התקבל R² = 0.399