Aplicación de la librería stargazer para presentar modelos corregidos con estimadores HAC
1. Calculo del Modelo
library(foreign)
library(stargazer)
datos.regresion <- read.dta("https://stats.idre.ucla.edu/stat/data/crime.dta")
modelo.estimado.1 <- lm(crime~poverty+single,data=datos.regresion)
stargazer(modelo.estimado.1, type = "html", title = "Modelo Estimado")
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 |
2. Librería Stargazer para Modelos Robustos a Autocorrelación de primer orden
library(lmtest)
library(stargazer)
library(sandwich)
## Modelo no corregido (Por defecto) y Corregido (Calculo Robusto)
estimacion.omega <- vcovHC(modelo.estimado.1,type = "HC1")
Robusto <- sqrt(diag(estimacion.omega))
stargazer(modelo.estimado.1, modelo.estimado.1, se = list(NULL, Robusto),
column.labels = c("Por Defecto", "Calculo Robusto"), align = T,
type = "html",
title="Errores Robustos a Autocorrelación de Primer Orden")
Dependent variable: | ||
crime | ||
Por Defecto | Calculo Robusto | |
(1) | (2) | |
poverty | 6.787 | 6.787 |
(8.989) | (10.927) | |
single | 166.373*** | 166.373*** |
(19.423) | (26.234) | |
Constant | -1,368.189*** | -1,368.189*** |
(187.205) | (284.918) | |
Observations | 51 | 51 |
R2 | 0.707 | 0.707 |
Adjusted R2 | 0.695 | 0.695 |
Residual Std. Error (df = 48) | 243.610 | 243.610 |
F Statistic (df = 2; 48) | 57.964*** | 57.964*** |
Note: | p<0.1; p<0.05; p<0.01 |
3. Librería Stargazer para Modelos Robustos a Autocorrelación de orden dos
estimacion.omega.2 <- NeweyWest(modelo.estimado.1,lag = 2)
Robusto.2 <- sqrt(diag(estimacion.omega.2))
stargazer(modelo.estimado.1, modelo.estimado.1, se = list(NULL, Robusto.2),
column.labels = c("Por defecto", "Robusto Orden 2"), align = T,
type = "html",
title="Errores Robustos a Autocorrelación de Orden 2")
Dependent variable: | ||
crime | ||
Por defecto | Robusto Orden 2 | |
(1) | (2) | |
poverty | 6.787 | 6.787 |
(8.989) | (10.594) | |
single | 166.373*** | 166.373*** |
(19.423) | (25.915) | |
Constant | -1,368.189*** | -1,368.189*** |
(187.205) | (303.847) | |
Observations | 51 | 51 |
R2 | 0.707 | 0.707 |
Adjusted R2 | 0.695 | 0.695 |
Residual Std. Error (df = 48) | 243.610 | 243.610 |
F Statistic (df = 2; 48) | 57.964*** | 57.964*** |
Note: | p<0.1; p<0.05; p<0.01 |