Subimos estas librerías a la sesión:
library(ARDL) #principal paquete para modelos ARDL
## To cite the ARDL package in publications:
##
## Use this reference to refer to the validity of the ARDL package.
##
## Natsiopoulos, Kleanthis, and Tzeremes, Nickolaos G. (2022). ARDL
## bounds test for cointegration: Replicating the Pesaran et al. (2001)
## results for the UK earnings equation using R. Journal of Applied
## Econometrics, 37(5), 1079-1090. https://doi.org/10.1002/jae.2919
##
## Use this reference to cite this specific version of the ARDL package.
##
## Kleanthis Natsiopoulos and Nickolaos Tzeremes (2023). ARDL: ARDL, ECM
## and Bounds-Test for Cointegration. R package version 0.2.3.
## https://CRAN.R-project.org/package=ARDL
library(dynamac) #otro paquete para modelos ARDL
library(urca)
library(zoo)
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
library(xts)
Veamos unas series monetarias de Dinamarca entre 1974:Q1 y 1987:Q3:
data(denmark)
head(denmark)
## ENTRY LRM LRY LPY IBO IDE
## 1 1974:01 11.63255 5.903658 -0.6187359 0.1547356 0.0940
## 2 1974:02 11.60415 5.873820 -0.5807479 0.1779912 0.0955
## 3 1974:03 11.58152 5.837818 -0.5428478 0.1705647 0.0955
## 4 1974:04 11.60185 5.812255 -0.5046041 0.1522273 0.0955
## 5 1975:01 11.58630 5.803945 -0.4864585 0.1342276 0.0885
## 6 1975:02 11.60450 5.786761 -0.4544386 0.1334805 0.0790
Veamos las series:
op <- par(mfrow=c(3,2))
ts.plot(denmark$LRM)
ts.plot(denmark$LRY)
ts.plot(denmark$LPY)
ts.plot(denmark$IBO)
ts.plot(denmark$IDE)
par(op)
Se busca estimar una funcion de demanda de dinero pero es facil cotejar que se trata de series no estacionarias con lo que un modelo de regresion lineal no sirve, pues daria lugar a una regresion espurea, salvo que fueran cointegradas.
Arranquemos con una regresion lineal
reglin <- lm(LRM ~ LRY + IBO + IDE, data = denmark)
summary(reglin)
##
## Call:
## lm(formula = LRM ~ LRY + IBO + IDE, data = denmark)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.093657 -0.028844 0.005755 0.030319 0.107622
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 4.39447 0.58112 7.562 7.07e-10 ***
## LRY 1.29580 0.09398 13.788 < 2e-16 ***
## IBO -2.61631 0.32819 -7.972 1.61e-10 ***
## IDE 0.61856 0.69110 0.895 0.375
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.04259 on 51 degrees of freedom
## Multiple R-squared: 0.9262, Adjusted R-squared: 0.9218
## F-statistic: 213.3 on 3 and 51 DF, p-value: < 2.2e-16
Tres de las cuatro variables explicativas son altamente significativas y el R2 es mayor a 0.90 Veamos los residuos.
plot(reglin, which=1)
¿Tienen raiz unitaria? Aplicamos el test de DF aumentado sin tendencia ni deriva
reglin.df <- ur.df(y=reglin$residuals, type='none',lags=4, selectlags=c("AIC"))
summary(reglin.df)
##
## ###############################################
## # Augmented Dickey-Fuller Test Unit Root Test #
## ###############################################
##
## Test regression none
##
##
## Call:
## lm(formula = z.diff ~ z.lag.1 - 1 + z.diff.lag)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.065498 -0.019002 0.000187 0.013667 0.087873
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## z.lag.1 -0.57890 0.15007 -3.857 0.000362 ***
## z.diff.lag1 0.04196 0.15413 0.272 0.786684
## z.diff.lag2 0.45206 0.14902 3.034 0.004004 **
## z.diff.lag3 0.36536 0.15716 2.325 0.024655 *
## z.diff.lag4 0.18900 0.13708 1.379 0.174773
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.02953 on 45 degrees of freedom
## Multiple R-squared: 0.3638, Adjusted R-squared: 0.2931
## F-statistic: 5.146 on 5 and 45 DF, p-value: 0.0008118
##
##
## Value of test-statistic is: -3.8575
##
## Critical values for test statistics:
## 1pct 5pct 10pct
## tau1 -2.6 -1.95 -1.61
Como el valor del estadístico es mayor en valor absoluto que el valor crítico, se encuentra que hay cointegración entre las variables. Podemos correr el modelo ARDL con corrección de error ¿Cuántos rezagos? Veamos la función auto.ardl. Con auto_ardl se determina la mejor especificación del modelo. Se incluyen hasta 5 rezagos por cada variable (recuerden que se trata de datos trimestrales)
modelos <- auto_ardl(LRM ~ LRY + IBO + IDE, data = denmark, max_order = 5)
Los mejores 20 modelos según el criterio AIC son:
modelos$top_orders
## LRM LRY IBO IDE AIC
## 1 3 1 3 2 -251.0259
## 2 3 1 3 3 -250.1144
## 3 2 2 0 0 -249.6266
## 4 3 2 3 2 -249.1087
## 5 3 2 3 3 -248.1858
## 6 2 2 0 1 -247.7786
## 7 2 1 0 0 -247.5643
## 8 2 2 1 1 -246.6885
## 9 3 3 3 3 -246.3061
## 10 2 2 1 2 -246.2709
## 11 2 1 1 1 -245.8736
## 12 2 2 2 2 -245.7722
## 13 1 1 0 0 -245.6620
## 14 2 1 2 2 -245.1712
## 15 3 1 2 2 -245.0996
## 16 1 0 0 0 -244.4317
## 17 1 1 0 1 -243.7702
## 18 5 5 5 5 -243.3120
## 19 4 1 3 2 -243.0728
## 20 4 1 3 3 -242.4378
El mejor modelo es el ARDL(3,1,3,2):
modelos$best_order
## LRM LRY IBO IDE
## 3 1 3 2
Creamos el objeto ardl_3132 con el mejor modelo:
ardl_3132 <- modelos$best_model
summary(ardl_3132)
##
## Time series regression with "ts" data:
## Start = 4, End = 55
##
## Call:
## dynlm::dynlm(formula = full_formula, data = data, start = start,
## end = end)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.029939 -0.008856 -0.002562 0.008190 0.072577
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 2.6202 0.5678 4.615 4.19e-05 ***
## L(LRM, 1) 0.3192 0.1367 2.336 0.024735 *
## L(LRM, 2) 0.5326 0.1324 4.024 0.000255 ***
## L(LRM, 3) -0.2687 0.1021 -2.631 0.012143 *
## LRY 0.6728 0.1312 5.129 8.32e-06 ***
## L(LRY, 1) -0.2574 0.1472 -1.749 0.088146 .
## IBO -1.0785 0.3217 -3.353 0.001790 **
## L(IBO, 1) -0.1062 0.5858 -0.181 0.857081
## L(IBO, 2) 0.2877 0.5691 0.505 0.616067
## L(IBO, 3) -0.9947 0.3925 -2.534 0.015401 *
## IDE 0.1255 0.5545 0.226 0.822161
## L(IDE, 1) -0.3280 0.7213 -0.455 0.651847
## L(IDE, 2) 1.4079 0.5520 2.550 0.014803 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.0191 on 39 degrees of freedom
## Multiple R-squared: 0.988, Adjusted R-squared: 0.9843
## F-statistic: 266.8 on 12 and 39 DF, p-value: < 2.2e-16
Como es un modelo en primeras diferencias, debemos introducir la corrección del término de error. Un modelo irrestricto con corrección del término de error (UECM en ingles) se obtiene simplemente con la función uecm():
uecm_3132 <- uecm(ardl_3132)
summary(uecm_3132)
##
## Time series regression with "ts" data:
## Start = 4, End = 55
##
## Call:
## dynlm::dynlm(formula = full_formula, data = data, start = start,
## end = end)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.029939 -0.008856 -0.002562 0.008190 0.072577
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 2.62019 0.56777 4.615 4.19e-05 ***
## L(LRM, 1) -0.41685 0.09166 -4.548 5.15e-05 ***
## L(LRY, 1) 0.41538 0.11761 3.532 0.00108 **
## L(IBO, 1) -1.89172 0.39111 -4.837 2.09e-05 ***
## L(IDE, 1) 1.20534 0.44690 2.697 0.01028 *
## d(L(LRM, 1)) -0.26394 0.10192 -2.590 0.01343 *
## d(L(LRM, 2)) 0.26867 0.10213 2.631 0.01214 *
## d(LRY) 0.67280 0.13116 5.129 8.32e-06 ***
## d(IBO) -1.07852 0.32170 -3.353 0.00179 **
## d(L(IBO, 1)) 0.70701 0.46874 1.508 0.13953
## d(L(IBO, 2)) 0.99468 0.39251 2.534 0.01540 *
## d(IDE) 0.12546 0.55445 0.226 0.82216
## d(L(IDE, 1)) -1.40786 0.55204 -2.550 0.01480 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.0191 on 39 degrees of freedom
## Multiple R-squared: 0.7458, Adjusted R-squared: 0.6676
## F-statistic: 9.537 on 12 and 39 DF, p-value: 3.001e-08
bounds_f_test(uecm_3132, case = 2)
##
## Bounds F-test (Wald) for no cointegration
##
## data: d(LRM) ~ L(LRM, 1) + L(LRY, 1) + L(IBO, 1) + L(IDE, 1) + d(L(LRM, 1)) + d(L(LRM, 2)) + d(LRY) + d(IBO) + d(L(IBO, 1)) + d(L(IBO, 2)) + d(IDE) + d(L(IDE, 1))
## F = 5.1168, p-value = 0.004418
## alternative hypothesis: Possible cointegration
## null values:
## k T
## 3 1000
Se rechaza la hipótesis nula de ausencia de cointegración
bounds_t_test(uecm_3132, case = 3)
##
## Bounds t-test for no cointegration
##
## data: d(LRM) ~ L(LRM, 1) + L(LRY, 1) + L(IBO, 1) + L(IDE, 1) + d(L(LRM, 1)) + d(L(LRM, 2)) + d(LRY) + d(IBO) + d(L(IBO, 1)) + d(L(IBO, 2)) + d(IDE) + d(L(IDE, 1))
## t = -4.5479, p-value = 0.005538
## alternative hypothesis: Possible cointegration
## null values:
## k T
## 3 1000
Como existe cointegración, el modelo está CORRECTAMENTE especificado. Si se aceptara la hipótesis nula, todos los regresores (i.e. variables independientes) serían estacionarios, con lo cual, no habría cointegración.
multipliers(uecm_3132, type = "sr")
## Term Estimate Std. Error t value Pr(>|t|)
## 1 (Intercept) 2.6201916 0.5677679 4.6148990 4.186867e-05
## 2 LRY 0.6727993 0.1311638 5.1294603 8.317401e-06
## 3 IBO -1.0785180 0.3217011 -3.3525465 1.790030e-03
## 4 IDE 0.1254643 0.5544522 0.2262852 8.221614e-01
multipliers(uecm_3132, type = "lr")
## Term Estimate Std. Error t value Pr(>|t|)
## 1 (Intercept) 6.2856579 0.7719160 8.142930 6.107445e-10
## 2 LRY 0.9964676 0.1239310 8.040503 8.358472e-10
## 3 IBO -4.5381160 0.5202961 -8.722180 1.058619e-10
## 4 IDE 2.8915201 0.9950853 2.905801 6.009239e-03
Graficamos:
ce <- coint_eq(ardl_3132, case = 2)
plot(ts(denmark$LRM, start=c(1974,1), frequency=4), xlab="",ylab="", ylim=c(11.5,12.2))
lines(ts(ce,start=c(1974,1), frequency=4),col=2)
legend(1974,12.10,"LRM",col=1,lty=1,bty="n",cex=0.7)
legend(1974,12.05,"ce",col=2,lty=1,bty="n",cex=0.7)
Usaremos la base de datos ineq, sobre actitudes frente a la desigualdad del ingreso en EE.UU. Fue utilizada por Graham Wright en su paper de 2017 “The political implications of American concerns about economic inequality”, publicado en Political Behavior 40(2): 321-346.
head(ineq)
## year mood urate concern demcontrol incshare10 csentiment incshare01
## 1 1966 60.793 3.8 0.465 1 0.3198 97.0 0.0837
## 2 1967 61.332 3.8 0.475 1 0.3205 94.7 0.0843
## 3 1968 58.163 3.6 0.490 1 0.3198 94.2 0.0835
## 4 1969 54.380 3.5 0.507 0 0.3182 90.3 0.0802
## 5 1970 60.555 4.9 0.519 0 0.3151 75.8 0.0780
## 6 1971 64.077 5.9 0.531 0 0.3175 80.6 0.0779
-concern es la preocupación del público acerca de la desigualdad; -incshare10 es la participación en el ingreso total del 10% mas adinerado; -urate es la tasa de desempleo.
La hipotesis de Wright es que la preocupación sobre la desigualdad crece a medida que crece la desigualdad y que las condiciones económicas se deterioran. Operacionalmente, la preocupación depende de sus valores rezagados, del nivel de desigualdad, del cambio en los niveles de desigualdad, y de la tasa de desempleo de corto plazo.
Veamos primero las tres series:
op <- par(mfrow=c(1,3))
ts.plot(ineq$concern)
ts.plot(ineq$incshare10)
ts.plot(ineq$urate)
par(op)
Si corremos tests de raíces unitarias sobre la serie concern, comprobaremos que en niveles tiene una raíz unitaria, y en primeras diferencias es estacionaria.
Mejor modelo:
modelos_concern <- auto_ardl(concern ~ incshare10 + urate,
data = ineq, max_order = 5)
El mejor modelo es un ARDL(1,1,0):
modelos_concern$best_order
## concern incshare10 urate
## 1 1 0
Que corresponde a:
ardl_concern <- modelos_concern$best_model
summary(ardl_concern)
##
## Time series regression with "ts" data:
## Start = 2, End = 49
##
## Call:
## dynlm::dynlm(formula = full_formula, data = data, start = start,
## end = end)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.027126 -0.005911 0.001071 0.007642 0.030773
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1.231e-01 2.822e-02 4.363 7.89e-05 ***
## L(concern, 1) 8.304e-01 5.225e-02 15.892 < 2e-16 ***
## incshare10 7.625e-01 2.924e-01 2.608 0.01246 *
## L(incshare10, 1) -8.313e-01 2.950e-01 -2.819 0.00726 **
## urate 7.809e-05 1.127e-03 0.069 0.94510
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.01175 on 43 degrees of freedom
## Multiple R-squared: 0.8831, Adjusted R-squared: 0.8722
## F-statistic: 81.19 on 4 and 43 DF, p-value: < 2.2e-16
Correccion de errores:
uecm_concern <- uecm(ardl_concern)
summary(uecm_concern)
##
## Time series regression with "ts" data:
## Start = 2, End = 49
##
## Call:
## dynlm::dynlm(formula = full_formula, data = data, start = start,
## end = end)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.027126 -0.005911 0.001071 0.007642 0.030773
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1.231e-01 2.822e-02 4.363 7.89e-05 ***
## L(concern, 1) -1.696e-01 5.225e-02 -3.245 0.00227 **
## L(incshare10, 1) -6.881e-02 3.201e-02 -2.150 0.03724 *
## urate 7.809e-05 1.127e-03 0.069 0.94510
## d(incshare10) 7.625e-01 2.924e-01 2.608 0.01246 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.01175 on 43 degrees of freedom
## Multiple R-squared: 0.3608, Adjusted R-squared: 0.3014
## F-statistic: 6.069 on 4 and 43 DF, p-value: 0.0005795
Tests de cointegracion: El primer caso, bounds_f_test(uecm_concern, case = 1), da error.
bounds_f_test(uecm_concern, case = 2)
##
## Bounds F-test (Wald) for no cointegration
##
## data: d(concern) ~ L(concern, 1) + L(incshare10, 1) + urate + d(incshare10)
## F = 5.2212, p-value = 0.006601
## alternative hypothesis: Possible cointegration
## null values:
## k T
## 2 1000
bounds_f_test(uecm_concern, case = 3)
##
## Bounds F-test (Wald) for no cointegration
##
## data: d(concern) ~ L(concern, 1) + L(incshare10, 1) + urate + d(incshare10)
## F = 6.9613, p-value = 0.004874
## alternative hypothesis: Possible cointegration
## null values:
## k T
## 2 1000
Ambos tests muestran que existe cointegración. Es decir que incshare10 (en niveles) y concern estan cointegradas. Podemos, pues afirmar, que existe una relación de largo plazo entre ambas variables.
Multiplicadores de corto y largo plazo:
multipliers(uecm_concern, type = "sr")
## Term Estimate Std. Error t value Pr(>|t|)
## 1 (Intercept) 1.231418e-01 0.028223475 4.36309691 7.892115e-05
## 2 incshare10 7.809407e-05 0.001127479 0.06926432 9.451003e-01
## 3 urate 7.625382e-01 0.292352191 2.60828612 1.246389e-02
multipliers(uecm_concern, type = "lr")
## Term Estimate Std. Error t value Pr(>|t|)
## 1 (Intercept) 0.7261769972 0.111015945 6.54119549 5.963330e-08
## 2 incshare10 -0.4057627219 0.249104407 -1.62888616 1.106426e-01
## 3 urate 0.0004605271 0.006600403 0.06977257 9.446982e-01
Gráfico de la relación de largo:
ce_concern <- coint_eq(ardl_concern, case = 2)
plot(ts(ineq$concern, start=c(1966), end = c(2014)), xlab="",ylab="")
lines(ts(ce_concern,start=c(1966), end = c(2014)),col=2)
legend(1985,0.52,"Concern",col=1,lty=1,bty="n",cex=0.7)
legend(1985,0.5,"ce",col=2,lty=1,bty="n",cex=0.7)