#Estimacion del modelo
library(foreign)
library(stargazer)
datos_regresion <- read.dta("https://stats.idre.ucla.edu/stat/data/crime.dta")
modelo_crime <- lm(crime~poverty+single,data=datos_regresion)
stargazer(modelo_crime, 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 |
Correlación de primer orden
#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
#Correlación de primer orden
options(scipen = 99999)
library(lmtest)
library(sandwich)
estimacion_omega <- vcovHC(modelo_crime,type = "HC1")
coeftest(modelo_crime,vcov. = estimacion_omega)
##
## t test of coefficients:
##
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -1368.1887 284.9180 -4.8020 0.00001576624 ***
## poverty 6.7874 10.9273 0.6211 0.5374
## single 166.3727 26.2343 6.3418 0.00000007519 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Comparativa
Robusto <- sqrt(diag(estimacion_omega))
stargazer(modelo_crime, modelo_crime, se = list(NULL, Robusto),
column.labels = c("Sin corregir", "Corregido"), align = TRUE,
type = "html",
title="Comparativa")
| Dependent variable: | ||
| crime | ||
| Sin corregir | Corregido | |
| (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 | |
Para correlación de segundo orden
#Correlación de segundo orden
estimacion_omega2 <- NeweyWest(modelo_crime,lag = 2)
Robusto2 <- sqrt(diag(estimacion_omega2))
stargazer(modelo_crime, modelo_crime, se = list(NULL, Robusto2),
column.labels = c("Sin corregir", "Corregido 2"), align = TRUE,
type = "html",
title="Comparativa")
| Dependent variable: | ||
| crime | ||
| Sin corregir | Corregido 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 | |