library(WDI)
df = WDI(indicator=c(nfs='SP.POP.TOTL', enf='FP.CPI.TOTL.ZG' ), country=c('TR'),  start=2000, 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
## Zorunlu paket yükleniyor: zoo
df.ts <- ts(df, start=c(2000), end=c(2020),frequency=1)
df.ts<-df.ts[,c("nfs","enf")]
plot(df.ts[,"nfs"], ylab="nüfus")

df.ts<-df.ts[,c("nfs","enf")]
plot(df.ts[,"nfs"], ylab="nüfus")

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

gecikmeliun <- data.frame(cbind(df.ts[,"nfs"], lag(df.ts[,"nfs"],-1)))
names(gecikmeliun) <- c("nfs","nfs1gec")
head(gecikmeliun)
##        nfs  nfs1gec
## 1 63240196       NA
## 2 64192243 63240196
## 3 65145357 64192243
## 4 66089402 65145357
## 5 67010930 66089402
## 6 67903461 67010930
acf(df.ts[,"nfs"])

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

enflasyon <- df.ts[,"enf"]
deltanüfus <- diff(df.ts[,"nfs"])
plot(enflasyon)

plot(deltanüfus)

phillips.reg <- dynlm(enflasyon~deltanüfus)
summary(phillips.reg)
## 
## Time series regression with "ts" data:
## Start = 2001, End = 2020
## 
## Call:
## dynlm(formula = enflasyon ~ deltanüfus)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -10.224  -7.171  -3.163   0.762  38.671 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)
## (Intercept)  3.014e+01  1.764e+01   1.708    0.105
## deltanüfus  -1.513e-05  1.650e-05  -0.917    0.371
## 
## Residual standard error: 12.84 on 18 degrees of freedom
## Multiple R-squared:  0.04465,    Adjusted R-squared:  -0.008427 
## F-statistic: 0.8412 on 1 and 18 DF,  p-value: 0.3712
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 = 9.1715, df1 = 1, df2 = 17, p-value = 0.00758
bgtest(phillips.reg, order=1, type="Chisq")
## 
##  Breusch-Godfrey test for serial correlation of order up to 1
## 
## data:  phillips.reg
## LM test = 7.0088, df = 1, p-value = 0.008111
library(sandwich)
coeftest(phillips.reg, vcov.=vcovHAC(phillips.reg))
## 
## t test of coefficients:
## 
##                Estimate  Std. Error t value Pr(>|t|)
## (Intercept)  3.0136e+01  2.1731e+01  1.3867   0.1825
## deltanüfus  -1.5132e-05  1.7111e-05 -0.8844   0.3882
coeftest(phillips.reg, vcov.=NeweyWest(phillips.reg))
## 
## t test of coefficients:
## 
##                Estimate  Std. Error t value Pr(>|t|)
## (Intercept)  3.0136e+01  2.2939e+01  1.3137   0.2054
## deltanüfus  -1.5132e-05  1.9467e-05 -0.7773   0.4471
coeftest(phillips.reg, vcov.=kernHAC(phillips.reg))
## 
## t test of coefficients:
## 
##                Estimate  Std. Error t value Pr(>|t|)
## (Intercept)  3.0136e+01  2.2976e+01  1.3116   0.2061
## deltanüfus  -1.5132e-05  1.9548e-05 -0.7741   0.4489