Econometría II: VEC

Departamento de Economía

Carlos A. Yanes G.

2023-11-08

Paquetes con que se trabaja la sesión

Los paquetes que se van a utilizar en la sesión de hoy son:

Note

Para trabajar en esta ocasión vamos a usar los paquetes de :

library(pacman)
p_load(TSstudio, tidyverse, stats, urca, forecast, ggfortify, ggplot2, tseries, fpp2, vars, stargazer, lmtest, tsDyn)
  • Es importante resaltar el paquete vars, ya que con ellos trabajaremos. Algo de lo que se muestra en está el libro de (Enders 2012) y desde luego el de (Hamilton 2020)

Preambulo

Introducción: Modelos VEC

  • Respecto a las especificaciones multivariadas en series de tiempo, hasta el momento se ha hablado de modelos de regresión que requieren la exogeneidad y estacionariedad de las variables, además de modelos VAR que permiten observar las relaciones dinámicas entre variables que presentan doble causalidad

  • Una evolución de una serie como:

Introducción: Modelos VEC

  • En general una combinación lineal de variables I(1), también es I(1). Sin embargo, en algunas situaciones esa combinación puede ser I(0), es decir estacionaria. Si existe al menos una combinación lineal de este tipo, se dice que hay una ecuación o relación cointegración, o que las variables se “mueven a la vez”, es decir, están ligadas.

  • Así, existe cointegración cuando una combinación lineal tiene un orden de integración menor al de las variables!

\[\beta_1y_{1t}+\beta_2y_{2t}+\cdots+\beta_py_{tp}=\varepsilon_t\]

  • Lo que explica lo anterior es que en el caso de dos variables I(1), las tendencias estocásticas se parecerán mucho y al combinarlas se eliminará el error no estacionario (esto es cointegración)

Introducción: Modelos VEC

  • Los modelos VEC permiten entre otras cosas, poner a prueba teorías económicas como:
  1. Teoría Cuantitativa del dinero \(Log(M)= v + log(p)+log(y)\)
  2. Función de producción \(Log\;Y = \alpha\; log\;K+(1-\alpha)\;log\,L\)
  3. Hipótesis de Fischer: \(i = r+\pi\)
  4. El poder de paridad de compra (PPP)
  5. La tasa de cambio Neutral (NATREX)
  6. La hipótesis de la forward rate insesgada
  • También resultan útiles para analizar fenómenos como el cambio climático en donde se involucran variables como la temperatura de la tierra y el mar, además de la radiación solar, CO2 o aerosol volcánico

Introducción: Modelos VEC

  • Si se tiene \[Y_{t}=\beta_{0}+\beta_{1}X_{t}+\epsilon_{t}\] Entonces si \(Y_{t}\) y \(X_{t}\) no son estacionarias pero \(\epsilon_{t}\)

  • Si, existe una relación de cointegración, dada por: \[\epsilon_{t}=Y_{t} -\beta_{0}-\beta_{1}X_{t}\]

Para que sirven los VEC?

  • Los VAR no son estacionarios.
  • Existe después de una estimación tipo M.C.O un error estacionario, ya sea en niveles o en diferencias de las variables \(\Delta Y_{t}\).
  • Sirven para hacer pronósticos.

Test de cointegración de Johansen’s

  • Primero especifique un modelo VAR para \(Y_t\) (en niveles, no en diferencias)
  • Determine el número de vectores de cointegración usando la traza y el test del eigenvector
  • Estime el VEC (vector de corrección del error)

VEC en sí

  • Parta de un modelo VAR(1) tal como: \(y_t=A_1y_{t-1}+ \varepsilon_t\) o lo que es: \[y_{1,t}= a_{11}y_{1,t-1}+a_{12}y_{2,t-1}+\varepsilon_{1,t}\] \[y_{2,t}= a_{21}y_{1,t-1}+a_{22}y_{2,t-1}+\varepsilon_{2,t}\]
  • Debemos sustraer \(y_{i,t-1}\) de la ecuación \(i\) para obtener \(\Delta y_t= \Pi y_{t-1}+ \varepsilon_t\), donde \(\Pi=-(I-A_1)\).
  • Luego de un gran juego de algebra vamos a tener: \[\Delta y_{1,t}= \alpha_1(y_{1, t-1}+ \beta_2 y_{2,t-1})+\varepsilon_{1,t}\] \[\Delta y_{2,t}= \alpha_2(y_{1, t-1}+ \beta_2 y_{2,t-1})+\varepsilon_{2,t}\]

VEC

Datos

Investigación de relación de largo plazo

  • Ingreso medido en miles de millones de pesos
  • Riqueza
  • Consumo
  • Frecuencia Trimestral
  • Primer trimestre de 1945

Datos a trabajar

Code
library(readxl)
data1 = read_excel("EjerciciosVEC.xlsx",sheet = "Ejemplo 1")
attach(data1)
Datos = ts(cbind(CONSUMO,INGRESO,RIQUEZA),start = 1945,frequency = 4)
head(Datos)
        CONSUMO INGRESO RIQUEZA
1945 Q1      NA      NA      NA
1945 Q2      NA      NA      NA
1945 Q3      NA      NA      NA
1945 Q4      NA      NA      NA
1946 Q1      NA      NA      NA
1946 Q2      NA      NA      NA
Code
plot(Datos)

Code
plot(log(Datos))

Primer paso

Estimar VAR

Code
periodo.muestra = time(Datos)>=1960 & time(Datos)<2008
log_Datos = ts(log(Datos[periodo.muestra,]),start = 1960,frequency = 4)
Code
plot(log_Datos)

Code
print(VARselect(log_Datos,type = "const"),digits = 3)
$selection
AIC(n)  HQ(n)  SC(n) FPE(n) 
     2      2      1      2 

$criteria
               1         2         3         4         5         6         7
AIC(n) -2.80e+01 -2.81e+01 -2.81e+01 -2.81e+01 -2.80e+01 -2.80e+01 -2.79e+01
HQ(n)  -2.80e+01 -2.80e+01 -2.79e+01 -2.78e+01 -2.77e+01 -2.76e+01 -2.75e+01
SC(n)  -2.78e+01 -2.78e+01 -2.76e+01 -2.74e+01 -2.72e+01 -2.70e+01 -2.68e+01
FPE(n)  6.60e-13  6.00e-13  6.07e-13  6.40e-13  6.75e-13  6.91e-13  7.38e-13
               8         9        10
AIC(n) -2.79e+01 -2.79e+01 -2.78e+01
HQ(n)  -2.74e+01 -2.73e+01 -2.72e+01
SC(n)  -2.66e+01 -2.64e+01 -2.62e+01
FPE(n)  7.72e-13  7.68e-13  8.20e-13
Code
modelo.MCO = lm(log(CONSUMO)~log(INGRESO)+log(RIQUEZA))
summary(modelo.MCO)

Call:
lm(formula = log(CONSUMO) ~ log(INGRESO) + log(RIQUEZA))

Residuals:
      Min        1Q    Median        3Q       Max 
-0.039395 -0.008729  0.000380  0.008936  0.076591 

Coefficients:
             Estimate Std. Error t value Pr(>|t|)    
(Intercept)  -1.87064    0.10381  -18.02   <2e-16 ***
log(INGRESO)  0.83179    0.01338   62.15   <2e-16 ***
log(RIQUEZA)  0.18627    0.01266   14.71   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 0.01507 on 253 degrees of freedom
  (28 observations deleted due to missingness)
Multiple R-squared:  0.9994,    Adjusted R-squared:  0.9994 
F-statistic: 2.261e+05 on 2 and 253 DF,  p-value: < 2.2e-16

Cointegración

Mecanismo de Cointegración

Code
residuos.MCO = ts(resid(modelo.MCO)[-(1:4)],start = c(1951,4),frequency = 4)
plot(residuos.MCO,type="l",main="Residuos de MCO"); abline(h=0)

Code
pp.test(residuos.MCO) # Se rechaza raiz

    Phillips-Perron Unit Root Test

data:  residuos.MCO
Dickey-Fuller Z(alpha) = -40.112, Truncation lag parameter = 5, p-value
= 0.01
alternative hypothesis: stationary
Code
summary(ca.jo(x = log_Datos,K = 2,ecdet = "const",type = "trace",spec = "longrun"))

###################### 
# Johansen-Procedure # 
###################### 

Test type: trace statistic , without linear trend and constant in cointegration 

Eigenvalues (lambda):
[1] 2.729757e-01 9.616285e-02 3.146071e-02 5.221747e-16

Values of teststatistic and critical values of test:

          test 10pct  5pct  1pct
r <= 2 |  6.07  7.52  9.24 12.97
r <= 1 | 25.28 17.85 19.96 24.60
r = 0  | 85.85 32.00 34.91 41.07

Eigenvectors, normalised to first column:
(These are the cointegration relations)

           CONSUMO.l2 INGRESO.l2 RIQUEZA.l2  constant
CONSUMO.l2  1.0000000  1.0000000  1.0000000  1.000000
INGRESO.l2 -2.0264208 -0.8945170  0.1248299  3.733255
RIQUEZA.l2  0.6008952 -0.1434732 -0.9592107 -5.148551
constant   -0.2971045  1.6758737  6.9265445 47.590938

Weights W:
(This is the loading matrix)

           CONSUMO.l2  INGRESO.l2   RIQUEZA.l2      constant
CONSUMO.d 0.005316310 -0.07976867  0.001887740  9.250845e-17
INGRESO.d 0.005889581  0.09844058 -0.006623956  7.342351e-15
RIQUEZA.d 0.006723621  0.25020530  0.027788748 -7.025859e-15
  • Al parecer por Johansen tenemos mas de una relación de cointegración
  • La prueba se hace con la referencia \(lag+1\). En este caso no se modifica el \(K\) orden del VAR original
  • Existen 3 restricciones adicionales a “const” en ca.jo tienen que ver con tendencia
  • Hay que saber no rechazar los rangos. Siempre se rechaza si el valor calculado es mayor al valor crítico de la prueba de rango \(\Pi\).

Segundo paso

Estimación VEC

Code
VEC = ca.jo(x = log_Datos,K = 2,ecdet = "none",type = "trace",spec = "longrun") #urca
summary(VEC)

###################### 
# Johansen-Procedure # 
###################### 

Test type: trace statistic , with linear trend 

Eigenvalues (lambda):
[1] 0.096742776 0.048966310 0.002287152

Values of teststatistic and critical values of test:

          test 10pct  5pct  1pct
r <= 2 |  0.44  6.50  8.18 11.65
r <= 1 |  9.97 15.66 17.95 23.52
r = 0  | 29.31 28.71 31.52 37.22

Eigenvectors, normalised to first column:
(These are the cointegration relations)

           CONSUMO.l2 INGRESO.l2 RIQUEZA.l2
CONSUMO.l2  1.0000000  1.0000000   1.000000
INGRESO.l2 -0.9005983 -0.2580060   2.569158
RIQUEZA.l2 -0.1391972 -0.6246733  -3.723030

Weights W:
(This is the loading matrix)

           CONSUMO.l2  INGRESO.l2   RIQUEZA.l2
CONSUMO.d -0.06231639 -0.01097364 0.0007254128
INGRESO.d  0.11912232 -0.02174770 0.0003315896
RIQUEZA.d  0.25857159  0.02414901 0.0019970729
Code
cajorls(VEC) # mostrar coeficientes parte VAR
$rlm

Call:
lm(formula = substitute(form1), data = data.mat)

Coefficients:
             CONSUMO.d  INGRESO.d  RIQUEZA.d
ect1         -0.06232    0.11912    0.25857 
constant     -0.09747    0.20309    0.43593 
CONSUMO.dl1   0.07388    0.39748    0.42530 
INGRESO.dl1   0.17114   -0.18616   -0.34362 
RIQUEZA.dl1   0.10043    0.07936    0.07866 


$beta
                 ect1
CONSUMO.l2  1.0000000
INGRESO.l2 -0.9005983
RIQUEZA.l2 -0.1391972
Code
summary(cajorls(VEC,r = 1)$rlm)
Response CONSUMO.d :

Call:
lm(formula = CONSUMO.d ~ ect1 + constant + CONSUMO.dl1 + INGRESO.dl1 + 
    RIQUEZA.dl1 - 1, data = data.mat)

Residuals:
       Min         1Q     Median         3Q        Max 
-0.0271749 -0.0040095  0.0001425  0.0038967  0.0141582 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
ect1        -0.06232    0.04059  -1.535 0.126470    
constant    -0.09747    0.06722  -1.450 0.148718    
CONSUMO.dl1  0.07388    0.07927   0.932 0.352571    
INGRESO.dl1  0.17114    0.06436   2.659 0.008526 ** 
RIQUEZA.dl1  0.10043    0.02687   3.738 0.000247 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 0.006256 on 185 degrees of freedom
Multiple R-squared:  0.6893,    Adjusted R-squared:  0.6809 
F-statistic: 82.09 on 5 and 185 DF,  p-value: < 2.2e-16


Response INGRESO.d :

Call:
lm(formula = INGRESO.d ~ ect1 + constant + CONSUMO.dl1 + INGRESO.dl1 + 
    RIQUEZA.dl1 - 1, data = data.mat)

Residuals:
      Min        1Q    Median        3Q       Max 
-0.020226 -0.004563 -0.000573  0.003711  0.035144 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
ect1         0.11912    0.05076   2.347   0.0200 *  
constant     0.20309    0.08405   2.416   0.0166 *  
CONSUMO.dl1  0.39748    0.09912   4.010  8.8e-05 ***
INGRESO.dl1 -0.18616    0.08048  -2.313   0.0218 *  
RIQUEZA.dl1  0.07936    0.03359   2.362   0.0192 *  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 0.007822 on 185 degrees of freedom
Multiple R-squared:  0.5788,    Adjusted R-squared:  0.5674 
F-statistic: 50.85 on 5 and 185 DF,  p-value: < 2.2e-16


Response RIQUEZA.d :

Call:
lm(formula = RIQUEZA.d ~ ect1 + constant + CONSUMO.dl1 + INGRESO.dl1 + 
    RIQUEZA.dl1 - 1, data = data.mat)

Residuals:
      Min        1Q    Median        3Q       Max 
-0.057527 -0.008693 -0.000253  0.009406  0.060255 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)  
ect1         0.25857    0.11504   2.248   0.0258 *
constant     0.43593    0.19048   2.289   0.0232 *
CONSUMO.dl1  0.42530    0.22464   1.893   0.0599 .
INGRESO.dl1 -0.34362    0.18239  -1.884   0.0611 .
RIQUEZA.dl1  0.07866    0.07613   1.033   0.3029  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 0.01773 on 185 degrees of freedom
Multiple R-squared:  0.2524,    Adjusted R-squared:  0.2322 
F-statistic: 12.49 on 5 and 185 DF,  p-value: 1.879e-10

Restricciones

Code
H0.B1 = matrix(c(1,0,0,0,0,1),ncol = 2);H0.B1 # restriccion para el ingreso
     [,1] [,2]
[1,]    1    0
[2,]    0    0
[3,]    0    1
Code
summary(blrtest(z = VEC,H=H0.B1,r = 1))

###################### 
# Johansen-Procedure # 
###################### 

Estimation and testing under linear restrictions on beta 

The VECM has been estimated subject to: 
beta=H*phi and/or alpha=A*psi

     [,1] [,2]
[1,]    1    0
[2,]    0    0
[3,]    0    1

Eigenvalues of restricted VAR (lambda):
[1] 0.0491 0.0032

The value of the likelihood ratio test statistic:
9.77 distributed as chi square with 1 df.
The p-value of the test statistic is: 0 

Eigenvectors, normalised to first column
of the restricted VAR:

        [,1]   [,2]
[1,]  1.0000  1.000
[2,]  0.0000  0.000
[3,] -0.8182 -1.067

Weights W of the restricted VAR:

             [,1]   [,2]
CONSUMO.d -0.0074 0.0019
INGRESO.d -0.0162 0.0027
RIQUEZA.d  0.0154 0.0113
Code
H0.B2 = matrix(c(1,0,0,0,1,0),ncol = 2);H0.B2 # restriccion para la riqueza
     [,1] [,2]
[1,]    1    0
[2,]    0    1
[3,]    0    0
Code
summary(blrtest(z = VEC,H=H0.B2,r = 1))

###################### 
# Johansen-Procedure # 
###################### 

Estimation and testing under linear restrictions on beta 

The VECM has been estimated subject to: 
beta=H*phi and/or alpha=A*psi

     [,1] [,2]
[1,]    1    0
[2,]    0    1
[3,]    0    0

Eigenvalues of restricted VAR (lambda):
[1] 0.0719 0.0241

The value of the likelihood ratio test statistic:
5.16 distributed as chi square with 1 df.
The p-value of the test statistic is: 0.02 

Eigenvectors, normalised to first column
of the restricted VAR:

        [,1]    [,2]
[1,]  1.0000  1.0000
[2,] -1.0673 -0.9805
[3,]  0.0000  0.0000

Weights W of the restricted VAR:

             [,1]    [,2]
CONSUMO.d -0.0071 -0.0221
INGRESO.d  0.0994 -0.0160
RIQUEZA.d  0.0548  0.0325

Tercer paso

Pronostico y Varianza

Code
irf(vec2var(VEC),response = "CONSUMO",boot = T) # VEC debe ser expresado

Impulse response coefficients
$CONSUMO
          CONSUMO
 [1,] 0.006172798
 [2,] 0.007640963
 [3,] 0.008138124
 [4,] 0.008237730
 [5,] 0.008254741
 [6,] 0.008246862
 [7,] 0.008235228
 [8,] 0.008224056
 [9,] 0.008214439
[10,] 0.008206382
[11,] 0.008199699

$INGRESO
          CONSUMO
 [1,] 0.000000000
 [2,] 0.001315733
 [3,] 0.001383194
 [4,] 0.001497816
 [5,] 0.001544576
 [6,] 0.001583415
 [7,] 0.001612896
 [8,] 0.001637079
 [9,] 0.001656900
[10,] 0.001673251
[11,] 0.001686747

$RIQUEZA
          CONSUMO
 [1,] 0.000000000
 [2,] 0.001701022
 [3,] 0.002337428
 [4,] 0.002530839
 [5,] 0.002598798
 [6,] 0.002628421
 [7,] 0.002645874
 [8,] 0.002658337
 [9,] 0.002668110
[10,] 0.002676038
[11,] 0.002682549


Lower Band, CI= 0.95 
$CONSUMO
          CONSUMO
 [1,] 0.005335945
 [2,] 0.006266286
 [3,] 0.006421669
 [4,] 0.006385752
 [5,] 0.006340580
 [6,] 0.006277441
 [7,] 0.006273361
 [8,] 0.006268744
 [9,] 0.006263545
[10,] 0.006258741
[11,] 0.006252220

$INGRESO
            CONSUMO
 [1,]  0.000000e+00
 [2,]  3.346801e-04
 [3,]  7.759075e-05
 [4,] -2.614855e-04
 [5,] -3.952587e-04
 [6,] -4.604307e-04
 [7,] -5.166335e-04
 [8,] -5.636159e-04
 [9,] -6.026145e-04
[10,] -6.579131e-04
[11,] -7.145872e-04

$RIQUEZA
           CONSUMO
 [1,] 0.0000000000
 [2,] 0.0009516230
 [3,] 0.0012835783
 [4,] 0.0013450226
 [5,] 0.0012226592
 [6,] 0.0011705740
 [7,] 0.0011172879
 [8,] 0.0010682538
 [9,] 0.0010257559
[10,] 0.0009894036
[11,] 0.0009586073


Upper Band, CI= 0.95 
$CONSUMO
          CONSUMO
 [1,] 0.006973769
 [2,] 0.008533184
 [3,] 0.009016550
 [4,] 0.009267249
 [5,] 0.009455751
 [6,] 0.009509204
 [7,] 0.009540653
 [8,] 0.009558411
 [9,] 0.009577052
[10,] 0.009604150
[11,] 0.009626831

$INGRESO
          CONSUMO
 [1,] 0.000000000
 [2,] 0.002039816
 [3,] 0.002570441
 [4,] 0.003051673
 [5,] 0.003422196
 [6,] 0.003612129
 [7,] 0.003738412
 [8,] 0.003825452
 [9,] 0.003895309
[10,] 0.003958168
[11,] 0.004010474

$RIQUEZA
          CONSUMO
 [1,] 0.000000000
 [2,] 0.002474581
 [3,] 0.003440555
 [4,] 0.003729904
 [5,] 0.003914284
 [6,] 0.004019725
 [7,] 0.004046613
 [8,] 0.004072500
 [9,] 0.004114521
[10,] 0.004151198
[11,] 0.004179626
Code
plot(irf(vec2var(VEC),response = "CONSUMO",boot = T))

Code
fevd(x = vec2var(VEC),n.ahead = 20)$CONSUMO
        CONSUMO    INGRESO    RIQUEZA
 [1,] 1.0000000 0.00000000 0.00000000
 [2,] 0.9542625 0.01712109 0.02861642
 [3,] 0.9313098 0.02085862 0.04783155
 [4,] 0.9178033 0.02343631 0.05876037
 [5,] 0.9093186 0.02518529 0.06549610
 [6,] 0.9034195 0.02655791 0.07002260
 [7,] 0.8990237 0.02768605 0.07329023
 [8,] 0.8955764 0.02864484 0.07577877
 [9,] 0.8927744 0.02947530 0.07775031
[10,] 0.8904375 0.03020380 0.07935874
[11,] 0.8884510 0.03084857 0.08070045
[12,] 0.8867378 0.03142302 0.08183919
[13,] 0.8852434 0.03193752 0.08281906
[14,] 0.8839279 0.03240034 0.08367173
[15,] 0.8827611 0.03281826 0.08442067
[16,] 0.8817194 0.03319691 0.08508372
[17,] 0.8807842 0.03354104 0.08567473
[18,] 0.8799406 0.03385470 0.08620469
[19,] 0.8791762 0.03414137 0.08668241
[20,] 0.8784809 0.03440405 0.08711507
Code
pronostico=predict(vec2var(VEC), n.ahead = 10)
plot(pronostico)

Gracias por su atención!!

Referencias

Enders, Walter. 2012. “Applied Econometric Time Series.” Privredna Kretanja i Ekonomska Politika 132: 93.
Hamilton, James D. 2020. Time Series Analysis. Princeton university press.