Modelo Estimado

options(scipen = 999999)
library(stargazer)
library(foreign)
datos_crime <- read.dta("https://stats.idre.ucla.edu/stat/data/crime.dta")
modelo.crime<-lm(crime~poverty+single,data=datos_crime)
stargazer(modelo.crime,
          title = "Modelo Crime", type = "html")
Modelo Crime
Dependent variable:
crime
poverty 6.787
(8.989)
single 166.373***
(19.423)
Constant -1,368.189***
(187.205)
Observations 51
R2 0.707
Adjusted R2 0.695
Residual Std. Error 243.610 (df = 48)
F Statistic 57.964*** (df = 2; 48)
Note: p<0.1; p<0.05; p<0.01

Pruebas de Heterocedasticidad y Autocottelación

- Prueba de White (BP)

library(lmtest)
BP_test<-bptest(modelo.crime,~I(poverty^2)+I(single^2)+poverty*single,data = datos_crime)
print(BP_test)
## 
##  studentized Breusch-Pagan test
## 
## data:  modelo.crime
## BP = 10.73, df = 5, p-value = 0.057

Hay evidencia de Heterocedasticidad porque el Pvalue 0.057 < 0.05

- Autocorrelación de 1° Orden (DW)

library(car)
durbinWatsonTest(model =  modelo.crime)
##  lag Autocorrelation D-W Statistic p-value
##    1     -0.07014421      2.040007   0.994
##  Alternative hypothesis: rho != 0

No hay evidencia de Autocorrelación de 1° orden porque el Pvalue > 0.05

- Autocorrelación de 2° orden Multiplicador de Lagrange (BG)

library(lmtest)
BG_test<-bgtest(modelo.crime,order = 2)
print(BG_test)
## 
##  Breusch-Godfrey test for serial correlation of order up to 2
## 
## data:  modelo.crime
## LM test = 0.27165, df = 2, p-value = 0.873

No hay evidencia de Autocorrelación de 2° orden porque el Pvalue > 0.05

Estimación Robusta (Estimador HAC)

Sin corregir

options(scipen = 99999)
library(lmtest)
coeftest(modelo.crime)
## 
## t test of coefficients:
## 
##               Estimate Std. Error t value         Pr(>|t|)    
## (Intercept) -1368.1887   187.2052 -7.3085 0.00000000247861 ***
## poverty         6.7874     8.9885  0.7551           0.4539    
## single        166.3727    19.4229  8.5658 0.00000000003117 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Corregido (Con estimador HAC)

options(scipen = 99999)
library(lmtest)
library(sandwich)
estimacion_corregida <- vcovHC(modelo.crime,type="HC0")

coeftest(modelo.crime,vcov. = estimacion_corregida)
## 
## t test of coefficients:
## 
##               Estimate Std. Error t value      Pr(>|t|)    
## (Intercept) -1368.1887   276.4111 -4.9498 0.00000956181 ***
## poverty         6.7874    10.6010  0.6403        0.5251    
## single        166.3727    25.4510  6.5370 0.00000003774 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Aplicación de libreria Stargazer para demostrar la comparativa del modelo sin corregir y el modelo corregido

options(scipen = 999999)
library(stargazer)
library(robustbase)
modelo.crime_robusto<-lmrob(crime~poverty+single,data=datos_crime)
stargazer(modelo.crime,modelo.crime_robusto,estimacion_corregida,title= "Comparativa",type = "html")
Comparativa
Dependent variable:
crime
OLS MM-type
linear
(1) (2)
poverty 6.787 11.466
(8.989) (9.263)
single 166.373*** 176.569***
(19.423) (23.223)
Constant -1,368.189*** -1,539.640***
(187.205) (235.765)
Observations 51 51
R2 0.707 0.795
Adjusted R2 0.695 0.787
Residual Std. Error (df = 48) 243.610 191.864
F Statistic 57.964*** (df = 2; 48)
Note: p<0.1; p<0.05; p<0.01
Comparativa
(Intercept) poverty single
(Intercept) 76,403.090 -703.845 -6,127.593
poverty -703.845 112.382 -69.274
single -6,127.593 -69.274 647.752