,
Datos_smoke <-load("C:\\Users\\MINEDUCYT\\Downloads\\Elder Ariel Perez Palacios - smoke.RData")
library(stargazer)
Modelo_Data <- lm(cigs ~ cigpric + lcigpric + income + lincome + age + agesq + educ + white + restaurn , data = data)
stargazer(Modelo_Data,title = "Modelo DESEMPLEO", type = "text")
##
## Modelo DESEMPLEO
## ===============================================
## Dependent variable:
## ---------------------------
## cigs
## -----------------------------------------------
## cigpric 2.002
## (1.493)
##
## lcigpric -115.273
## (85.424)
##
## income -0.00005
## (0.0001)
##
## lincome 1.404
## (1.708)
##
## age 0.778***
## (0.161)
##
## agesq -0.009***
## (0.002)
##
## educ -0.495***
## (0.168)
##
## white -0.531
## (1.461)
##
## restaurn -2.644**
## (1.130)
##
## Constant 340.804
## (260.016)
##
## -----------------------------------------------
## Observations 807
## R2 0.055
## Adjusted R2 0.044
## Residual Std. Error 13.413 (df = 797)
## F Statistic 5.169*** (df = 9; 797)
## ===============================================
## Note: *p<0.1; **p<0.05; ***p<0.01
library(lmtest)
prueba_white<-bptest(Modelo_Data,~I(cigpric^2) + I(lcigpric^2) + I(income^2) + I(lincome^2) + I(age^2) + I(agesq^2) + I(educ^2) + I(white^2) + I(restaurn^2),data = data)
print(prueba_white)
##
## studentized Breusch-Pagan test
##
## data: Modelo_Data
## BP = 26.323, df = 9, p-value = 0.001809
Como p-value < 0.05 Se rechaza la Ho, por lo tanto hay evidencia que la varianza de los residuos es heterocedástica.
library(lmtest)
bgtest(Modelo_Data,order = 2)
##
## Breusch-Godfrey test for serial correlation of order up to 2
##
## data: Modelo_Data
## LM test = 0.26889, df = 2, p-value = 0.8742
Como pvalue>0.05 No se rechaza H0 , por lo tanto se puede concluir que los residuos del modelo, no siguen autocorrelación de segundo orden.
library(lmtest)
bgtest(Modelo_Data,order = 1)
##
## Breusch-Godfrey test for serial correlation of order up to 1
##
## data: Modelo_Data
## LM test = 0.069737, df = 1, p-value = 0.7917
Como pvalue>0.05 No se rechaza H0 , por lo tanto se puede concluir que los residuos del modelo, no siguen autocorrelación de primer orden.
Para concluir, la matriz de varianza-covarianza del modelo no es escalar, ya que existe presencia de heterocedasticidad en nuestro modelo.
options(scipen = 99999)
library(lmtest)
library(sandwich)
estimacion_omega<-vcovHC(Modelo_Data,type = "HC0")
coeftest(Modelo_Data,vcov. = estimacion_omega)
##
## t test of coefficients:
##
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 340.804374604 278.565072885 1.2234 0.221530
## cigpric 2.002267667 1.602727983 1.2493 0.211927
## lcigpric -115.273464445 91.344424879 -1.2620 0.207331
## income -0.000046194 0.000115593 -0.3996 0.689540
## lincome 1.404061178 1.228970726 1.1425 0.253602
## age 0.778359013 0.136944678 5.6837 0.0000000184838 ***
## agesq -0.009150353 0.001451548 -6.3039 0.0000000004804 ***
## educ -0.494780616 0.162968371 -3.0361 0.002475 **
## white -0.531051635 1.361907703 -0.3899 0.696691
## restaurn -2.644241351 1.038254938 -2.5468 0.011058 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
library(sandwich)
cov <- vcovHC(Modelo_Data, type = "HC0")
robust.se <- sqrt(diag(cov))
stargazer(Modelo_Data, Modelo_Data , se=list(NULL, robust.se),
column.labels=c("Original","Corregido"), align=TRUE,type = "html", title = "Modelo Consumo de Cigarros")
| Dependent variable: | ||
| cigs | ||
| Original | Corregido | |
| (1) | (2) | |
| cigpric | 2.002 | 2.002 |
| (1.493) | (1.603) | |
| lcigpric | -115.273 | -115.273 |
| (85.424) | (91.344) | |
| income | -0.00005 | -0.00005 |
| (0.0001) | (0.0001) | |
| lincome | 1.404 | 1.404 |
| (1.708) | (1.229) | |
| age | 0.778*** | 0.778*** |
| (0.161) | (0.137) | |
| agesq | -0.009*** | -0.009*** |
| (0.002) | (0.001) | |
| educ | -0.495*** | -0.495*** |
| (0.168) | (0.163) | |
| white | -0.531 | -0.531 |
| (1.461) | (1.362) | |
| restaurn | -2.644** | -2.644** |
| (1.130) | (1.038) | |
| Constant | 340.804 | 340.804 |
| (260.016) | (278.565) | |
| Observations | 807 | 807 |
| R2 | 0.055 | 0.055 |
| Adjusted R2 | 0.044 | 0.044 |
| Residual Std. Error (df = 797) | 13.413 | 13.413 |
| F Statistic (df = 9; 797) | 5.169*** | 5.169*** |
| Note: | p<0.1; p<0.05; p<0.01 | |