#Import data setwd("C:/Andrzej/Dydaktyka/econometric_methods/") dataset <- read.csv("lecture_9_ecm.csv", sep = ";", dec = ",") #Convert series into time series objects l_real_wage <- ts(dataset$l_real_wage) l_productivity <- ts(dataset$l_productivity) unemployment <- ts(dataset$unemployment) #Unit root test sequences for 3 series to verify the necessary condition for cointegration #install.packages("fUnitRoots") library(fUnitRoots) #One can also use the function ur.df from package urca, where the lag length is selected based on info criteria for test regression. adfTest(l_real_wage, lags = 4, type = "c") adfTest(diff(l_real_wage, differences = 1) , lags = 4, type = "c") adfTest(l_productivity, lags = 4, type = "c") adfTest(diff(l_productivity, differences = 1) , lags = 4, type = "c") adfTest(unemployment, lags = 4, type = "c") adfTest(diff(unemployment, differences = 1) , lags = 4, type = "c") #Verifying the sufficient condition for cointegration coint.equation <- lm(l_real_wage ~ l_productivity + unemployment) summary(coint.equation) #The following is AN INCORRECT way to test residuals for nonstationarity (usual ADF): adfTest(resid(coint.equation), lags = 4, type = "c") #The following is THE CORRECT way to test residuals for nonstationarity (CIDF): #install.packages("aTSA") library(aTSA) coint.test(y = dataset$l_real_wage, X = as.matrix(cbind(dataset$l_productivity, dataset$unemployment))) #Estimating the error correction model ECT <- resid(coint.equation) plot(ECT) dataset.ts <- ts(cbind(dataset[, -1], ECT), frequency = 4, start = c(1967, 1)) library(dynlm) ECM.equation <- dynlm(d(l_real_wage) ~ L(ECT, 1) + d(l_productivity) + d(unemployment), data = dataset.ts) summary(ECM.equation)