1.Estimacion del modelo.

options(scipen = 9999999)
library(foreign)
library(haven)
library(stargazer)
crime <- read_dta("C:\\Users\\Emerson\\Downloads\\crime.dta")
modelo_crime<-lm(crime~poverty+single,data = crime)

stargazer(modelo_crime, type = "text", title = "Modelo Estimado")
## 
## 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.Libreria Stargazer para modelos robustos a autocorrelacion de primer orden.

library(lmtest)
library(stargazer)
library(sandwich)

## Modelo no corregido (Por defecto) y Corregido (Calculo Robusto)

estimacion.omega <- vcovHC(modelo_crime,type = "HC1")
Robusto <- sqrt(diag(estimacion.omega))
stargazer(modelo_crime, modelo_crime, se = list(NULL, Robusto),
          column.labels = c("Por Defecto", "Calculo Robusto"), align = T, 
          type = "text",
          title="Errores Robustos a Autocorrelación de Primer Orden")
## 
## 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.Libreria Stargazer para modelos robustos a autocorrelacion de segundo orden.

estimacion.omega.2 <- NeweyWest(modelo_crime,lag = 2)
Robusto.2 <- sqrt(diag(estimacion.omega.2))
stargazer(modelo_crime,modelo_crime, se = list(NULL, Robusto.2),
          column.labels = c("Por defecto", "Robusto Orden 2"), align = T,
          type = "text",
          title="Errores Robustos a Autocorrelación de Orden 2")
## 
## 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