library(WDI)
df = WDI(indicator=c(buyume='NY.GDP.MKTP.KD.ZG', enf='FP.CPI.TOTL.ZG' ), country=c('TR'),  start=1992, end=2020)
library(dynlm)
## Zorunlu paket yükleniyor: zoo
## Warning: package 'zoo' was built under R version 4.1.3
## 
## 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("buyume","enf")]
plot.ts(df.ts[, "buyume"], ylab = "buyumeorani")

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

gecikmelibuyume <- data.frame(cbind(df.ts[,"buyume"], lag(df.ts[,"buyume"],-1)))
names(gecikmelibuyume) <- c("buyume","buyume1gec")
head(gecikmelibuyume)
##      buyume buyume1gec
## 1  5.035635         NA
## 2  7.651265   5.035635
## 3 -4.668147   7.651265
## 4  7.878267  -4.668147
## 5  7.379664   7.878267
## 6  7.577664   7.379664
acf(df.ts[,"buyume"])

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

enflasyon <- df.ts[,"enf"]
deltabuyumeorani <- diff(df.ts[,"buyume"])
plot(enflasyon)

plot(deltabuyumeorani)

phillips.reg <- dynlm(enflasyon~deltabuyumeorani)
summary(phillips.reg)
## 
## Time series regression with "ts" data:
## Start = 1993, End = 2020
## 
## Call:
## dynlm(formula = enflasyon ~ deltabuyumeorani)
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -28.31 -24.52 -19.75  26.93  68.35 
## 
## Coefficients:
##                  Estimate Std. Error t value Pr(>|t|)    
## (Intercept)       32.6164     6.2798   5.194 2.02e-05 ***
## deltabuyumeorani  -0.3447     0.9730  -0.354    0.726    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 33.22 on 26 degrees of freedom
## Multiple R-squared:  0.004802,   Adjusted R-squared:  -0.03347 
## F-statistic: 0.1255 on 1 and 26 DF,  p-value: 0.726
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 = 152.69, df1 = 1, df2 = 25, p-value = 3.824e-12
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 = 24.061, df = 1, p-value = 9.336e-07
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)      32.61640    9.36541  3.4826 0.001773 **
## deltabuyumeorani -0.34465    0.70715 -0.4874 0.630074   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
coeftest(phillips.reg, vcov.=NeweyWest(phillips.reg))
## Warning in meatHAC(x, order.by = order.by, prewhite = prewhite, weights =
## weights, : more weights than observations, only first n used
## 
## t test of coefficients:
## 
##                  Estimate Std. Error t value Pr(>|t|)   
## (Intercept)      32.61640   28.48870  1.1449 0.262685   
## deltabuyumeorani -0.34465    0.11510 -2.9944 0.005966 **
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
coeftest(phillips.reg, vcov.=kernHAC(phillips.reg))
## 
## t test of coefficients:
## 
##                  Estimate Std. Error t value Pr(>|t|)
## (Intercept)      32.61640   30.35638  1.0744   0.2925
## deltabuyumeorani -0.34465    0.73047 -0.4718   0.6410