R Markdown
library(WDI)
df = WDI(indicator=c(isz='SL.UEM.TOTL.ZS', 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
df.ts <- ts(df, start=c(2000), end=c(2020),frequency=1)
df.ts<-df.ts[,c("isz","enf")]
plot(df.ts[,"isz"], ylab="nüfus")

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

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

gecikmeliun <- data.frame(cbind(df.ts[,"isz"], lag(df.ts[,"isz"],-1)))
names(gecikmeliun) <- c("isz","nfs1gec")
head(gecikmeliun)
## isz nfs1gec
## 1 6.50 NA
## 2 8.38 6.50
## 3 10.36 8.38
## 4 10.54 10.36
## 5 10.84 10.54
## 6 10.64 10.84
acf(df.ts[,"isz"])

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

enflasyon <- df.ts[,"enf"]
deltanüfus <- diff(df.ts[,"isz"])
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
## -17.522 -6.818 -2.826 2.956 34.300
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 12.908 2.762 4.673 0.000189 ***
## deltanüfus 3.826 2.011 1.903 0.073220 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 11.99 on 18 degrees of freedom
## Multiple R-squared: 0.1674, Adjusted R-squared: 0.1212
## F-statistic: 3.62 on 1 and 18 DF, p-value: 0.07322
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 = 5.2813, df1 = 1, df2 = 17, p-value = 0.03452
bgtest(phillips.reg, order=1, type="Chisq")
##
## Breusch-Godfrey test for serial correlation of order up to 1
##
## data: phillips.reg
## LM test = 4.7406, df = 1, p-value = 0.02946
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) 12.9081 2.7187 4.7479 0.0001607 ***
## deltanüfus 3.8256 3.1559 1.2122 0.2410963
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
coeftest(phillips.reg, vcov.=NeweyWest(phillips.reg))
##
## t test of coefficients:
##
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 12.9081 1.8314 7.0480 1.417e-06 ***
## deltanüfus 3.8256 1.9348 1.9773 0.06353 .
## ---
## 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) 12.9081 2.1310 6.0573 1.002e-05 ***
## deltanüfus 3.8256 2.1161 1.8079 0.08737 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1