Autor: Guillermo Martinez Atilano
El siguiente Modelo fue estimado con R.
Utiliza la base de datos Auto.dta de Stata.
2018-08-03 00:30:44
> articulo <- readXL(“C:/Users/Atilano/Desktop/auto_es.xls”, rownames=FALSE, header=TRUE, na=””,
+ sheet=”Sheet1″, stringsAsFactors=TRUE)
La gráfica de dispersión muestra una relación negativa entre el peso de un automóvil y las millas por galón. A memor peso aumenta el rendimiento y se obtienen mayor millaje.
> RegModel.1 <- lm(mpg~peso, data=articulo)
> summary(RegModel.1)
Call:
lm(formula = mpg ~ peso, data = articulo)
Residuals:
Min 1Q Median 3Q Max
-6.9593 -1.9325 -0.3713 0.8885 13.8174
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 39.4402835 1.6140031 24.44 <2e-16 ***
peso -0.0060087 0.0005179 -11.60 <2e-16 ***
—
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ‘ 1
Residual standard error: 3.439 on 72 degrees of freedom
Multiple R-squared: 0.6515, Adjusted R-squared: 0.6467
F-statistic: 134.6 on 1 and 72 DF, p-value: < 2.2e-16
El resultado obtenido
> stargazer(RegModel.1, header=FALSE, type = “text”, title=”Tabla 1. Modelos estimados”,
+ digits=2, single.row=FALSE, omit.stat=c(“LL”,”ser”,”f”))
Tabla 1. Modelos estimados Millas por galón vs. peso del auto
> articulo$mpg100 <- with(articulo, mpg/100)
> RegModel.2 <- lm(mpg100~peso, data=articulo)
> summary(RegModel.2)
Call:
lm(formula = mpg100 ~ peso, data = articulo)
Residuals:
Min 1Q Median 3Q Max
-0.069593 -0.019325 -0.003713 0.008885 0.138174
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.394402835 0.016140031 24.44 <2e-16 ***
peso -0.000060087 0.000005179 -11.60 <2e-16 ***
—
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ‘ 1
Residual standard error: 0.03439 on 72 degrees of freedom
Multiple R-squared: 0.6515, Adjusted R-squared: 0.6467
F-statistic: 134.6 on 1 and 72 DF, p-value: < 2.2e-16
___________________________________________________________________________
> articulo$mpg100 <- with(articulo, 100/mpg)
> RegModel.3 <- lm(mpg100~peso, data=articulo)
> summary(RegModel.3)
Call:
lm(formula = mpg100 ~ peso, data = articulo)
Residuals:
Min 1Q Median 3Q Max
-2.04508 -0.37487 0.00488 0.40990 1.56000
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.7707669 0.3142571 2.453 0.0166 *
peso 0.0014070 0.0001008 13.954 <2e-16 ***
—
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ‘ 1
Residual standard error: 0.6696 on 72 degrees of freedom
Multiple R-squared: 0.73, Adjusted R-squared: 0.7263
F-statistic: 194.7 on 1 and 72 DF, p-value: < 2.2e-16
___________________________________________________________________________
> RegModel.4 <- lm(mpg100~peso+precio, data=articulo)
> summary(RegModel.4)
Call:
lm(formula = mpg100 ~ peso + precio, data = articulo)
Residuals:
Min 1Q Median 3Q Max
-2.55540 -0.27285 0.02426 0.40080 1.32384
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.77124601 0.30497650 2.529 0.0137 *
peso 0.00126102 0.00011614 10.858 <2e-16 ***
precio 0.00007144 0.00003060 2.334 0.0224 *
—
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ‘ 1
Residual standard error: 0.6498 on 71 degrees of freedom
Multiple R-squared: 0.7493, Adjusted R-squared: 0.7422
F-statistic: 106.1 on 2 and 71 DF, p-value: < 2.2e-16
> stargazer(RegModel.1, header=FALSE, type = “text”,
+ title=”Tabla 1. Modelos estimados”,
+ digits=2, single.row=FALSE, omit.stat=c(“LL”,”ser”,”f”))
Tabla 1. Modelos estimados
========================================
Variable dependiente : mpg
—————————————-
peso -0.01***
(0.001)
Constante 39.44***
(1.61)
—————————————-
Observationes 74
R2 0.65
Adjusted R2 0.65
========================================
Note: *p<0.1; **p<0.05; ***p<0.01
___________________________________________________________________________
> stargazer(RegModel.4, header=FALSE, type = “text”,
+ title=”Tabla 1. Modelos estimados”,
+ digits=2, single.row=FALSE, omit.stat=c(“LL”,”ser”,”f”))
Tabla 2. Modelos estimados : 100/mpg vs. peso. (se interpreta por cada 100 millas cuantos galones se consumen)
========================================
Dependent variable:
—————————
mpg100
—————————————-
peso 0.001***
(0.0001)
precio 0.0001**
(0.0000)
Constant 0.77**
(0.30)
—————————————-
Observations 74
R2 0.75
Adjusted R2 0.74
========================================
Note: *p<0.1; **p<0.05; ***p<0.01
___________________________________________________________________________
> stargazer(RegModel.3, RegModel.4, header=FALSE, type = “text”,
+ title=”Tabla 1. Modelos estimados”,
+ digits=2, single.row=FALSE, omit.stat=c(“LL”,”ser”,”f”))
Tabla 3. Modelos estimados son 2. con una variable y con dos variables explicativas.
=========================================
Dependent variable:
—————————-
mpg100
(1) (2)
—————————————–
peso 0.001*** 0.001***
(0.0001) (0.0001)
precio 0.0001**
(0.0000)
Constant 0.77** 0.77**
(0.31) (0.30)
——————————————————————–
Observations 74 74
R2 0.73 0.75
Adjusted R2 0.73 0.74
=========================================
Note: *p<0.1; **p<0.05; ***p<0.01