library(tseries)
## Warning: package 'tseries' was built under R version 3.2.5
library(stats)
consum=read.csv("C:/Users/Lukas/Desktop/Ekonometrie/AKM/NEW!!!/Cviceni/kointegrace/consum.csv")
Consumer Price Index for All Urban Consumers: All Items, Index 1982-1984=100, Monthly, Seasonally Adjusted
M2 Money Stock, Billions of Dollars, Monthly, Seasonally Adjusted
\(log(CPI)_t=\beta_0+\beta_1 log(M2)_t+\epsilon_t\)
par(mfrow=c(2,1))
plot.ts(GDP, main="M2")
plot.ts(Cons, main="CPI")
adf.test(con_per)
##
## Augmented Dickey-Fuller Test
##
## data: con_per
## Dickey-Fuller = -1.9524, Lag order = 2, p-value = 0.5905
## alternative hypothesis: stationary
adf.test(gdp_per)
##
## Augmented Dickey-Fuller Test
##
## data: gdp_per
## Dickey-Fuller = -2.8191, Lag order = 2, p-value = 0.2604
## alternative hypothesis: stationary
Zkusíme jeste dalsí test na stacionaritu. KPSS test. POZOR u KPSS testu je alternativní hypotéza unit roor!
kpss.test(gdp_per, null = "Trend")
## Warning in kpss.test(gdp_per, null = "Trend"): p-value greater than printed
## p-value
##
## KPSS Test for Trend Stationarity
##
## data: gdp_per
## KPSS Trend = 0.10581, Truncation lag parameter = 1, p-value = 0.1
kpss.test(con_per, null = "Trend")
##
## KPSS Test for Trend Stationarity
##
## data: con_per
## KPSS Trend = 0.15399, Truncation lag parameter = 1, p-value =
## 0.04334
Prikloníme se k hypotéze, ze CPI není trendove stacionární casová rada. Obsahuje tedy minimálne jeden jednotkový koren. Musíme zjisti, kolik jich má.
Abychom se vyznali v kodu, tak si radeji jiz zadefinujeme logaritmus. Zároven se casto setkáte v makroekonomii, ze jsou malými písmeny znaceny logaritmus promenných.
adf.test(diff(gdp_per))
##
## Augmented Dickey-Fuller Test
##
## data: diff(gdp_per)
## Dickey-Fuller = -3.2431, Lag order = 2, p-value = 0.09957
## alternative hypothesis: stationary
adf.test(diff(con_per))
##
## Augmented Dickey-Fuller Test
##
## data: diff(con_per)
## Dickey-Fuller = -2.2277, Lag order = 2, p-value = 0.4856
## alternative hypothesis: stationary
kpss.test(diff(con_per))
## Warning in kpss.test(diff(con_per)): p-value greater than printed p-value
##
## KPSS Test for Level Stationarity
##
## data: diff(con_per)
## KPSS Level = 0.15019, Truncation lag parameter = 1, p-value = 0.1
kpss.test(diff(gdp_per))
## Warning in kpss.test(diff(gdp_per)): p-value greater than printed p-value
##
## KPSS Test for Level Stationarity
##
## data: diff(gdp_per)
## KPSS Level = 0.07965, Truncation lag parameter = 1, p-value = 0.1
adf.test(diff(GDP))
##
## Augmented Dickey-Fuller Test
##
## data: diff(GDP)
## Dickey-Fuller = -3.2528, Lag order = 2, p-value = 0.09822
## alternative hypothesis: stationary
adf.test(diff(Cons))
##
## Augmented Dickey-Fuller Test
##
## data: diff(Cons)
## Dickey-Fuller = -2.2357, Lag order = 2, p-value = 0.4826
## alternative hypothesis: stationary
Zdá se, ze obe promenné jsou jiz stacionární. U \(\Delta gdp_per\) muzeme H0 zamítnout pro \(\alpha<0.01\) a u \(\Deltacpi\) pro \(\alpha<0.05\) . Tedy, m2 a cpi jsou procesy integrovany rádu 1, I(1).
Ekonomická teorie, nám ríká, ze by mel existovat slouhodobý vztah mezi spotrebou a duchodem. Pojdme to tedy otestovat.
dl_vztah=lm(con_per~gdp_per)
summary(dl_vztah)
##
## Call:
## lm(formula = con_per ~ gdp_per)
##
## Residuals:
## Min 1Q Median 3Q Max
## -746.75 -350.89 -14.82 329.58 1003.94
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -2.243e+03 4.106e+02 -5.463 1.29e-05 ***
## gdp_per 8.787e-01 1.007e-02 87.222 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 515.6 on 24 degrees of freedom
## Multiple R-squared: 0.9969, Adjusted R-squared: 0.9967
## F-statistic: 7608 on 1 and 24 DF, p-value: < 2.2e-16
Provedeme residuálné test kointegrace. Pokud totiz jsou obe promenné kointegrované, tak vznikla residua musí být I(0), neboli nesmi obsahovat jednotkový koren, neboli musí být stacionární.
residua_con=dl_vztah$residuals
adf.test(residua_con)
##
## Augmented Dickey-Fuller Test
##
## data: residua_con
## Dickey-Fuller = -2.9263, Lag order = 2, p-value = 0.2195
## alternative hypothesis: stationary
kpss.test(residua_con)
## Warning in kpss.test(residua_con): p-value greater than printed p-value
##
## KPSS Test for Level Stationarity
##
## data: residua_con
## KPSS Level = 0.13282, Truncation lag parameter = 1, p-value = 0.1
resid_1=c(residua_con[2:length(residua_con)])
dcon=diff(con_per)
dgdp=diff(gdp_per)
data=data.frame(dcon,dgdp,resid_1)
ecm=lm(diff(con_per)~diff(gdp_per)+resid_1, data = data)
summary(ecm)
##
## Call:
## lm(formula = diff(con_per) ~ diff(gdp_per) + resid_1, data = data)
##
## Residuals:
## Min 1Q Median 3Q Max
## -504.09 -135.26 -53.16 132.41 505.61
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 2.995e+02 1.152e+02 2.600 0.0163 *
## diff(gdp_per) 6.135e-01 8.135e-02 7.542 1.55e-07 ***
## resid_1 5.878e-04 1.191e-01 0.005 0.9961
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 246.3 on 22 degrees of freedom
## Multiple R-squared: 0.7912, Adjusted R-squared: 0.7723
## F-statistic: 41.69 on 2 and 22 DF, p-value: 3.281e-08