library(WDI)
df = WDI(indicator=c(un='SL.UEM.TOTL.ZS', enf='FP.CPI.TOTL.ZG' ), country=c('TR'), start=1992, end=2020)
library(dynlm)
## Zorunlu paket yükleniyor: zoo
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
df.ts <- ts(df, start=c(1992), end=c(2020),frequency=1)
df.ts<-df.ts[,c("un","enf")]
plot(df.ts[,"un"], ylab="iÅŸsizlik")

plot(df.ts[,"enf"], ylab="enflasyon")

gecikmeliun <- data.frame(cbind(df.ts[,"un"], lag(df.ts[,"un"],-1)))
names(gecikmeliun) <- c("un","un1gec")
head(gecikmeliun)
## un un1gec
## 1 8.51 NA
## 2 8.96 8.51
## 3 8.58 8.96
## 4 7.64 8.58
## 5 6.63 7.64
## 6 6.84 6.63
acf(df.ts[,"un"])

acf(df.ts[,"enf"])

enflasyon <- df.ts[,"enf"]
deltaissizlik <- diff(df.ts[,"un"])
plot(enflasyon)

phillips.reg <- dynlm(enflasyon~deltaissizlik)
summary(phillips.reg)
##
## Time series regression with "ts" data:
## Start = 1993, End = 2020
##
## Call:
## dynlm(formula = enflasyon ~ deltaissizlik)
##
## Residuals:
## Min 1Q Median 3Q Max
## -30.44 -24.05 -20.79 27.40 71.41
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 33.002 6.331 5.213 1.92e-05 ***
## deltaissizlik -2.103 5.163 -0.407 0.687
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 33.2 on 26 degrees of freedom
## Multiple R-squared: 0.00634, Adjusted R-squared: -0.03188
## F-statistic: 0.1659 on 1 and 26 DF, p-value: 0.6871
uhat <- resid(phillips.reg)
plot(uhat)

acf(uhat)

library(lmtest)
bgtest(phillips.reg, order=1, type="F")
##
## Breusch-Godfrey test for serial correlation of order up to 1
##
## data: phillips.reg
## LM test = 131.8, df1 = 1, df2 = 25, p-value = 1.844e-11
library(lmtest)
bgtest(phillips.reg, order=1, type="Chisq")
##
## Breusch-Godfrey test for serial correlation of order up to 1
##
## data: phillips.reg
## LM test = 23.536, df = 1, p-value = 1.226e-06
library(sandwich)
## Warning: package 'sandwich' was built under R version 4.1.3
coeftest(phillips.reg, vcov.=vcovHAC(phillips.reg))
##
## t test of coefficients:
##
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 33.0018 10.0679 3.2779 0.002968 **
## deltaissizlik -2.1029 4.9319 -0.4264 0.673334
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1