coint <- read_excel("C:/Users/Luz Véliz/OneDrive/Escritorio/U/Econometría II/Laboratorios/Lab 8/Cointegración en R.xls")
coint = as.data.frame(coint)
plot(coint$PCE, type="l")
plot(coint$GDP, type="l")
GDP.ts = ts(coint$GDP, start=c(1974,1), end=c(2007,4), frequency = 4)
PCE.ts = ts(coint$PCE, start=c(1974,1), end=c(2007,4), frequency = 4)
datos1=cbind(GDP.ts, PCE.ts)
plot(cbind(GDP.ts, PCE.ts))
cor(coint$PCE, coint$GDP)
## [1] 0.9991024
Se obtuvo que las variables seleccionadas tienen una fuerte correlación.
modelo1 = lm(PCE.ts ~ GDP.ts )
a <- VARselect(coint[,c(5,6)], lag.max=15,type="const")
a$selection
## AIC(n) HQ(n) SC(n) FPE(n)
## 4 3 2 4
En base a los valores obtenidos, se selecciona un valor de p=4.
modelos = VAR(datos1, p=4)
summary(modelos)
##
## VAR Estimation Results:
## =========================
## Endogenous variables: GDP.ts, PCE.ts
## Deterministic variables: const
## Sample size: 132
## Log Likelihood: -1188.245
## Roots of the characteristic polynomial:
## 1.005 0.9134 0.4394 0.4394 0.423 0.3982 0.3982 0.3635
## Call:
## VAR(y = datos1, p = 4)
##
##
## Estimation results for equation GDP.ts:
## =======================================
## GDP.ts = GDP.ts.l1 + PCE.ts.l1 + GDP.ts.l2 + PCE.ts.l2 + GDP.ts.l3 + PCE.ts.l3 + GDP.ts.l4 + PCE.ts.l4 + const
##
## Estimate Std. Error t value Pr(>|t|)
## GDP.ts.l1 0.85548 0.12197 7.014 1.36e-10 ***
## PCE.ts.l1 0.83104 0.20588 4.037 9.47e-05 ***
## GDP.ts.l2 -0.05410 0.15795 -0.343 0.7325
## PCE.ts.l2 -0.17992 0.27511 -0.654 0.5143
## GDP.ts.l3 0.03461 0.15774 0.219 0.8267
## PCE.ts.l3 -0.45185 0.28894 -1.564 0.1204
## GDP.ts.l4 0.06005 0.11315 0.531 0.5966
## PCE.ts.l4 -0.04400 0.23504 -0.187 0.8518
## const 24.11753 11.88746 2.029 0.0446 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
##
## Residual standard error: 34.22 on 123 degrees of freedom
## Multiple R-Squared: 0.9991, Adjusted R-squared: 0.999
## F-statistic: 1.678e+04 on 8 and 123 DF, p-value: < 2.2e-16
##
##
## Estimation results for equation PCE.ts:
## =======================================
## PCE.ts = GDP.ts.l1 + PCE.ts.l1 + GDP.ts.l2 + PCE.ts.l2 + GDP.ts.l3 + PCE.ts.l3 + GDP.ts.l4 + PCE.ts.l4 + const
##
## Estimate Std. Error t value Pr(>|t|)
## GDP.ts.l1 -7.728e-05 7.092e-02 -0.001 0.999
## PCE.ts.l1 1.129e+00 1.197e-01 9.432 3.18e-16 ***
## GDP.ts.l2 -8.435e-02 9.183e-02 -0.918 0.360
## PCE.ts.l2 1.650e-01 1.600e-01 1.032 0.304
## GDP.ts.l3 2.420e-02 9.171e-02 0.264 0.792
## PCE.ts.l3 -1.681e-01 1.680e-01 -1.001 0.319
## GDP.ts.l4 5.174e-02 6.579e-02 0.787 0.433
## PCE.ts.l4 -1.099e-01 1.367e-01 -0.804 0.423
## const 6.502e+00 6.911e+00 0.941 0.349
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
##
## Residual standard error: 19.89 on 123 degrees of freedom
## Multiple R-Squared: 0.9993, Adjusted R-squared: 0.9993
## F-statistic: 2.274e+04 on 8 and 123 DF, p-value: < 2.2e-16
##
##
##
## Covariance matrix of residuals:
## GDP.ts PCE.ts
## GDP.ts 1170.7 450.7
## PCE.ts 450.7 395.7
##
## Correlation matrix of residuals:
## GDP.ts PCE.ts
## GDP.ts 1.0000 0.6621
## PCE.ts 0.6621 1.0000
residuos <- resid(modelos)
adf.test(residuos[,1])
## Augmented Dickey-Fuller Test
## alternative: stationary
##
## Type 1: no drift no trend
## lag ADF p.value
## [1,] 0 -11.13 0.01
## [2,] 1 -7.84 0.01
## [3,] 2 -6.52 0.01
## [4,] 3 -5.51 0.01
## [5,] 4 -4.94 0.01
## Type 2: with drift no trend
## lag ADF p.value
## [1,] 0 -11.09 0.01
## [2,] 1 -7.80 0.01
## [3,] 2 -6.50 0.01
## [4,] 3 -5.49 0.01
## [5,] 4 -4.92 0.01
## Type 3: with drift and trend
## lag ADF p.value
## [1,] 0 -11.04 0.01
## [2,] 1 -7.76 0.01
## [3,] 2 -6.47 0.01
## [4,] 3 -5.47 0.01
## [5,] 4 -4.90 0.01
## ----
## Note: in fact, p.value = 0.01 means p.value <= 0.01
adf.test(residuos[,2])
## Augmented Dickey-Fuller Test
## alternative: stationary
##
## Type 1: no drift no trend
## lag ADF p.value
## [1,] 0 -11.37 0.01
## [2,] 1 -7.86 0.01
## [3,] 2 -6.24 0.01
## [4,] 3 -5.50 0.01
## [5,] 4 -5.40 0.01
## Type 2: with drift no trend
## lag ADF p.value
## [1,] 0 -11.33 0.01
## [2,] 1 -7.83 0.01
## [3,] 2 -6.21 0.01
## [4,] 3 -5.48 0.01
## [5,] 4 -5.38 0.01
## Type 3: with drift and trend
## lag ADF p.value
## [1,] 0 -11.29 0.01
## [2,] 1 -7.79 0.01
## [3,] 2 -6.19 0.01
## [4,] 3 -5.47 0.01
## [5,] 4 -5.36 0.01
## ----
## Note: in fact, p.value = 0.01 means p.value <= 0.01
Se obtuvo que los valores resultantes son menores a 0.05, por lo tanto sí hay cointegración en base a esta prueba.
prueba.P0 = ca.po(datos1, type="Pz")
prueba.P2 = ca.po(datos1, type="Pu")
summary(prueba.P0)
##
## ########################################
## # Phillips and Ouliaris Unit Root Test #
## ########################################
##
## Test of type Pz
## detrending of series none
##
## Response GDP.ts :
##
## Call:
## lm(formula = GDP.ts ~ zr - 1)
##
## Residuals:
## Min 1Q Median 3Q Max
## -150.279 -18.515 2.796 27.331 141.137
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## zrGDP.ts 0.95334 0.03958 24.089 <2e-16 ***
## zrPCE.ts 0.08483 0.06116 1.387 0.168
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 37.23 on 133 degrees of freedom
## Multiple R-squared: 0.9999, Adjusted R-squared: 0.9999
## F-statistic: 5.421e+05 on 2 and 133 DF, p-value: < 2.2e-16
##
##
## Response PCE.ts :
##
## Call:
## lm(formula = PCE.ts ~ zr - 1)
##
## Residuals:
## Min 1Q Median 3Q Max
## -104.417 -8.223 1.965 11.714 48.952
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## zrGDP.ts 0.007454 0.021281 0.35 0.727
## zrPCE.ts 0.996942 0.032886 30.32 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 20.02 on 133 degrees of freedom
## Multiple R-squared: 0.9999, Adjusted R-squared: 0.9999
## F-statistic: 7.855e+05 on 2 and 133 DF, p-value: < 2.2e-16
##
##
##
## Value of test-statistic is: 13.4923
##
## Critical values of Pz are:
## 10pct 5pct 1pct
## critical values 33.9267 40.8217 55.1911
summary(prueba.P2)
##
## ########################################
## # Phillips and Ouliaris Unit Root Test #
## ########################################
##
## Test of type Pu
## detrending of series none
##
##
## Call:
## lm(formula = z[, 1] ~ z[, -1] - 1)
##
## Residuals:
## Min 1Q Median 3Q Max
## -185.94 -32.81 29.65 77.98 145.10
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## z[, -1] 1.54450 0.00323 478.1 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 81.14 on 135 degrees of freedom
## Multiple R-squared: 0.9994, Adjusted R-squared: 0.9994
## F-statistic: 2.286e+05 on 1 and 135 DF, p-value: < 2.2e-16
##
##
## Value of test-statistic is: 13.4278
##
## Critical values of Pu are:
## 10pct 5pct 1pct
## critical values 20.3933 25.9711 38.3413
En las pruebas de Philips y Oularis se obtuvo que el valor estadístico de prueba es menor a los valores críticos de cada prueba.
En base a las pruebas realizadas anteriormente, se determina que los residuos del modelo son estacionarios, por lo tanto existe una relación fuerte a largo plazo entre las variables del modelo (existe cointegración).
Previamente se creó un modelo con las variables seleccionadas de la base de datos y se sustrajeron los residuos del mismo, con los cuales se evaluó la existencia de cointegración. Posterior a la confirmación de que existe cointegración, se aplicarán diferenciaciones a las variables de entrada, lo cual posibilita la detección y corrección de errores con mayor precisión.
dlnPCE = diff(PCE.ts)
dlnGDP = diff(GDP.ts)
modelo3 = lm(dlnPCE~dlnGDP)
summary(modelo3)
##
## Call:
## lm(formula = dlnPCE ~ dlnGDP)
##
## Residuals:
## Min 1Q Median 3Q Max
## -55.171 -6.835 -0.706 7.283 40.057
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 7.82308 1.58733 4.928 2.42e-06 ***
## dlnGDP 0.36719 0.03443 10.665 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 14.98 on 133 degrees of freedom
## Multiple R-squared: 0.461, Adjusted R-squared: 0.4569
## F-statistic: 113.7 on 1 and 133 DF, p-value: < 2.2e-16
res3=modelo3$residuals
res3_1 = lag(res3)
MCE = lm(dlnPCE ~ dlnGDP + res3_1)
summary(MCE)
##
## Call:
## lm(formula = dlnPCE ~ dlnGDP + res3_1)
##
## Residuals:
## Min 1Q Median 3Q Max
## -51.325 -6.831 -0.756 7.618 39.266
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 7.24990 1.61223 4.497 1.5e-05 ***
## dlnGDP 0.38558 0.03576 10.781 < 2e-16 ***
## res3_1 -0.15209 0.08988 -1.692 0.093 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 14.91 on 131 degrees of freedom
## (1 observation deleted due to missingness)
## Multiple R-squared: 0.4742, Adjusted R-squared: 0.4661
## F-statistic: 59.06 on 2 and 131 DF, p-value: < 2.2e-16
MCE$coefficients[3]
## res3_1
## -0.1520933
abs(MCE$coefficients[3])
## res3_1
## 0.1520933
En base al modelo generado anteriormente con tres componentes, se obtuvo que el coeficiente de los residuos es -0.1520933, el cual es negativo y en valor absoluto es menor a 1. Por lo tanto, se determina que existe una relación a corto plazo entre las variables PCE y GDP.