Estimando el modelo
options(scipen = 9999999)
library(foreign)
library(haven)
library(stargazer)
crime <- read_dta("https://stats.idre.ucla.edu/stat/data/crime.dta")
crimen_modelo<-lm(crime~poverty+single,data = crime)
stargazer(crimen_modelo, 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 |
Utilizando estimadores HAC para primer orden
library(lmtest)
library(stargazer)
library(sandwich)
## Modelo no corregido y corregido
estimacion.omega <- vcovHC(crimen_modelo,type = "HC1")
Robusto <- sqrt(diag(estimacion.omega))
stargazer(crimen_modelo, crimen_modelo, se = list(NULL, Robusto),
column.labels = c("Por Defecto", "Calculo Robusto"), align = T,
type = "html",
title="Errores Robustos de 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 | |
Utilizando estimadores HAC para segundo orden
estimacion_omega_2 <- NeweyWest(crimen_modelo,lag = 2)
Robusto_2 <- sqrt(diag(estimacion_omega_2))
stargazer(crimen_modelo,crimen_modelo, se = list(NULL, Robusto_2),
column.labels = c("Por defecto", "Robusto Orden 2"), align = T,
type = "html",
title="Errores Robustos de Autocorrelación de segundo orden")| 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 | |