#========= VAR PADRÃOdados_var <-tibble(log_despesa =log(as.numeric(despesa_real_tri_sa)),log_pib =log(as.numeric(pib_real_tri_sa)),log_receita =log(as.numeric(receita_real_tri_sa)))#Seleção do número de defasagenslagselect <-VARselect(dados_var, lag.max =8, type ="const")lagselect
#Funções de Impulso-Resposta (IRF)#Ordem de Grangerirf_var_padrão_pib <-irf(var_model,impulse =c("log_pib", "log_despesa", "log_receita"),response =c("log_pib"),n.ahead =36, boot =TRUE) plot(irf_var_padrão_pib)
#Testes de robustez / Diagnóstico#Teste de autocorrelação dos resíduos (LM test)serial.test(var_model, lags.pt =16, type ="PT.asymptotic")
Portmanteau Test (asymptotic)
data: Residuals of VAR object var_model
Chi-squared = 121.74, df = 135, p-value = 0.7864
#Teste de normalidade dos resíduosnormality.test(var_model)
$JB
JB-Test (multivariate)
data: Residuals of VAR object var_model
Chi-squared = 2546.1, df = 6, p-value < 0.00000000000000022
$Skewness
Skewness only (multivariate)
data: Residuals of VAR object var_model
Chi-squared = 252.81, df = 3, p-value < 0.00000000000000022
$Kurtosis
Kurtosis only (multivariate)
data: Residuals of VAR object var_model
Chi-squared = 2293.3, df = 3, p-value < 0.00000000000000022
## Teste de heterocedasticidade (ARCH LM test)arch.test(var_model, lags.multi =12)
ARCH (multivariate)
data: Residuals of VAR object var_model
Chi-squared = 449.31, df = 432, p-value = 0.273
#Estabilidade do modelo (roots dentro do círculo unitário)roots(var_model) #estabilidade
[1] 0.9889224 0.4696088 0.2294131
#========= VAR EM 1° DIFERENÇAdados_var_diff <-tibble(d_log_despesa =diff(log(as.numeric(despesa_real_tri_sa))),d_log_pib =diff(log(as.numeric(pib_real_tri_sa))),d_log_receita =diff(log(as.numeric(receita_real_tri_sa))))#Seleção do número de defasagenslagselect <-VARselect(dados_var_diff, lag.max =8, type ="const")lagselect
#========= VECM#========= TESTE DE COINTEGRAÇÃO (Johansen)# Determinar número de defasagens (p) para o VECMlagselect <-VARselect(dados_var, lag.max =8, type ="const")lagselect
# Rodar teste de Johansenvec_test <-ca.jo(dados_var, type ="trace", K =2, ecdet ="const", spec ="transitory")summary(vec_test) # número de relações de cointegração
######################
# Johansen-Procedure #
######################
Test type: trace statistic , without linear trend and constant in cointegration
Eigenvalues (lambda):
[1] 0.328575247205597387179 0.214399621246646548967 0.173171171238841348217
[4] 0.000000000000003996803
Values of teststatistic and critical values of test:
test 10pct 5pct 1pct
r <= 2 | 18.64 7.52 9.24 12.97
r <= 1 | 42.28 17.85 19.96 24.60
r = 0 | 81.32 32.00 34.91 41.07
Eigenvectors, normalised to first column:
(These are the cointegration relations)
log_despesa.l1 log_pib.l1 log_receita.l1 constant
log_despesa.l1 1.000000 1.00000000 1.000000 1.00000
log_pib.l1 -3.445401 -1.29087188 1.144834 -10.30656
log_receita.l1 2.084027 0.04471097 -2.926712 2.43120
constant 10.605893 5.32731660 8.364458 104.99142
Weights W:
(This is the loading matrix)
log_despesa.l1 log_pib.l1 log_receita.l1
log_despesa.d -0.03924814 -0.37630156 -0.004812536
log_pib.d 0.04115290 0.01145064 0.020458894
log_receita.d -0.23246106 0.11014225 0.079202754
constant
log_despesa.d 0.000000000000037723893
log_pib.d -0.000000000000006082256
log_receita.d 0.000000000000034495979
# Rodar teste de Johansenvec_test <-ca.jo(dados_var, type ="eigen", K =2, ecdet ="const", spec ="transitory")summary(vec_test)
######################
# Johansen-Procedure #
######################
Test type: maximal eigenvalue statistic (lambda max) , without linear trend and constant in cointegration
Eigenvalues (lambda):
[1] 0.328575247205597387179 0.214399621246646548967 0.173171171238841348217
[4] 0.000000000000003996803
Values of teststatistic and critical values of test:
test 10pct 5pct 1pct
r <= 2 | 18.64 7.52 9.24 12.97
r <= 1 | 23.65 13.75 15.67 20.20
r = 0 | 39.04 19.77 22.00 26.81
Eigenvectors, normalised to first column:
(These are the cointegration relations)
log_despesa.l1 log_pib.l1 log_receita.l1 constant
log_despesa.l1 1.000000 1.00000000 1.000000 1.00000
log_pib.l1 -3.445401 -1.29087188 1.144834 -10.30656
log_receita.l1 2.084027 0.04471097 -2.926712 2.43120
constant 10.605893 5.32731660 8.364458 104.99142
Weights W:
(This is the loading matrix)
log_despesa.l1 log_pib.l1 log_receita.l1
log_despesa.d -0.03924814 -0.37630156 -0.004812536
log_pib.d 0.04115290 0.01145064 0.020458894
log_receita.d -0.23246106 0.11014225 0.079202754
constant
log_despesa.d 0.000000000000037723893
log_pib.d -0.000000000000006082256
log_receita.d 0.000000000000034495979
# Estimar VECMvec_mod <-cajorls(vec_test, r =2)summary(vec_mod$rlm)
Response log_despesa.d :
Call:
lm(formula = log_despesa.d ~ ect1 + ect2 + log_despesa.dl1 +
log_pib.dl1 + log_receita.dl1 - 1, data = data.mat)
Residuals:
Min 1Q Median 3Q Max
-0.15240 -0.02510 -0.00669 0.01163 0.46098
Coefficients:
Estimate Std. Error t value Pr(>|t|)
ect1 -0.41555 0.10028 -4.144 0.0000752 ***
ect2 0.62098 0.24856 2.498 0.0142 *
log_despesa.dl1 -0.10275 0.09685 -1.061 0.2914
log_pib.dl1 -0.21170 0.44732 -0.473 0.6371
log_receita.dl1 -0.27439 0.11486 -2.389 0.0189 *
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 0.07367 on 93 degrees of freedom
Multiple R-squared: 0.3633, Adjusted R-squared: 0.3291
F-statistic: 10.61 on 5 and 93 DF, p-value: 0.00000004381
Response log_pib.d :
Call:
lm(formula = log_pib.d ~ ect1 + ect2 + log_despesa.dl1 + log_pib.dl1 +
log_receita.dl1 - 1, data = data.mat)
Residuals:
Min 1Q Median 3Q Max
-0.088441 -0.005552 0.006162 0.014484 0.076099
Coefficients:
Estimate Std. Error t value Pr(>|t|)
ect1 0.05260 0.02800 1.879 0.0634 .
ect2 -0.15657 0.06940 -2.256 0.0264 *
log_despesa.dl1 0.02960 0.02704 1.094 0.2766
log_pib.dl1 0.23444 0.12489 1.877 0.0636 .
log_receita.dl1 -0.03426 0.03207 -1.068 0.2882
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 0.02057 on 93 degrees of freedom
Multiple R-squared: 0.1419, Adjusted R-squared: 0.09578
F-statistic: 3.076 on 5 and 93 DF, p-value: 0.01295
Response log_receita.d :
Call:
lm(formula = log_receita.d ~ ect1 + ect2 + log_despesa.dl1 +
log_pib.dl1 + log_receita.dl1 - 1, data = data.mat)
Residuals:
Min 1Q Median 3Q Max
-0.47344 -0.01317 0.01951 0.05334 0.39693
Coefficients:
Estimate Std. Error t value Pr(>|t|)
ect1 -0.1223 0.1179 -1.038 0.3022
ect2 0.6587 0.2922 2.254 0.0265 *
log_despesa.dl1 0.2912 0.1139 2.558 0.0121 *
log_pib.dl1 0.8589 0.5259 1.633 0.1058
log_receita.dl1 -0.1145 0.1350 -0.848 0.3985
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 0.0866 on 93 degrees of freedom
Multiple R-squared: 0.2134, Adjusted R-squared: 0.1712
F-statistic: 5.047 on 5 and 93 DF, p-value: 0.0003888
# Transformar o resultado do ca.jo em um objeto VAR/VEC compatívelvec2var_mod <-vec2var(vec_test, r =2)#Testes de robustez / diagnóstico# Autocorrelação dos resíduos (Portmanteau)serial.test(vec2var_mod, lags.pt =12, type ="PT.asymptotic")
Portmanteau Test (asymptotic)
data: Residuals of VAR object vec2var_mod
Chi-squared = 91.227, df = 93, p-value = 0.5326
# Normalidade dos resíduosnormality.test(vec2var_mod)
$JB
JB-Test (multivariate)
data: Residuals of VAR object vec2var_mod
Chi-squared = 2048.2, df = 6, p-value < 0.00000000000000022
$Skewness
Skewness only (multivariate)
data: Residuals of VAR object vec2var_mod
Chi-squared = 233.16, df = 3, p-value < 0.00000000000000022
$Kurtosis
Kurtosis only (multivariate)
data: Residuals of VAR object vec2var_mod
Chi-squared = 1815.1, df = 3, p-value < 0.00000000000000022
# Calcule o impulso-resposta de um choque na receita sobre o pibirf_receita_pib <-irf(vec2var_mod, impulse ="log_receita", response ="log_pib", n.ahead =36, ci =0.95, boot =TRUE)plot(irf_receita_pib)