setwd("C:/Users/marcogeovanni/Desktop/Modern Guide To Econometrics/Chapter 8")
library(readstata13)
library(tseries)
## Warning: package 'tseries' was built under R version 3.2.4
library(ggplot2)
library(car)
## Warning: package 'car' was built under R version 3.2.3
library(egcm)
## Warning: package 'egcm' was built under R version 3.2.5
## Loading required package: zoo
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
## Loading required package: xts
## Warning: package 'xts' was built under R version 3.2.5
## Loading required package: TTR
## Warning: package 'TTR' was built under R version 3.2.5
library(fArma)
## Warning: package 'fArma' was built under R version 3.2.5
## Loading required package: timeDate
## Warning: package 'timeDate' was built under R version 3.2.3
## Loading required package: timeSeries
## Warning: package 'timeSeries' was built under R version 3.2.4
##
## Attaching package: 'timeSeries'
## The following object is masked from 'package:zoo':
##
## time<-
## Loading required package: fBasics
## Warning: package 'fBasics' was built under R version 3.2.4
##
## Rmetrics Package fBasics
## Analysing Markets and calculating Basic Statistics
## Copyright (C) 2005-2014 Rmetrics Association Zurich
## Educational Software for Financial Engineering and Computational Science
## Rmetrics is free software and comes with ABSOLUTELY NO WARRANTY.
## https://www.rmetrics.org --- Mail to: info@rmetrics.org
##
## Attaching package: 'fBasics'
## The following object is masked from 'package:TTR':
##
## volatility
## The following object is masked from 'package:car':
##
## densityPlot
PPP<- read.dta13("ppp2.dta")
attach(PPP)
summary(PPP)
## dateid01 cpieuro cpiuk cpius
## Min. :1988-01-01 Min. : 64.25 Min. : 61.90 Min. :115.7
## 1st Qu.:1993-09-23 1st Qu.: 79.23 1st Qu.: 82.58 1st Qu.:145.6
## Median :1999-06-16 Median : 87.91 Median : 92.35 Median :166.4
## Mean :1999-06-16 Mean : 88.79 Mean : 90.87 Mean :169.4
## 3rd Qu.:2005-03-08 3rd Qu.: 99.43 3rd Qu.: 99.40 3rd Qu.:193.6
## Max. :2010-12-01 Max. :111.29 Max. :116.80 Max. :220.0
## fxde fxdp fxep logcpieuro
## Min. :0.8516 Min. :1.397 Min. :1.084 Min. :4.605
## 1st Qu.:1.1274 1st Qu.:1.551 1st Qu.:1.264 1st Qu.:4.815
## Median :1.2429 Median :1.629 Median :1.417 Median :4.919
## Mean :1.2148 Mean :1.668 Mean :1.387 Mean :4.918
## 3rd Qu.:1.3105 3rd Qu.:1.780 3rd Qu.:1.485 3rd Qu.:5.042
## Max. :1.5971 Max. :2.045 Max. :1.700 Max. :5.155
## logcpiuk logcpius
## Min. :4.605 Min. :4.605
## 1st Qu.:4.893 1st Qu.:4.835
## Median :5.005 Median :4.969
## Mean :4.978 Mean :4.971
## 3rd Qu.:5.079 3rd Qu.:5.120
## Max. :5.240 Max. :5.248
LNUSPI<-log(cpius)
LNEUPI<-log(cpieuro)
LNfxde<-log(fxde)
PIratio<-LNUSPI-LNEUPI
IERDatabase<-data.frame(PIratio,dateid01,LNfxde)
ExchangeratevsPriceindexPlot<-ggplot(data=IERDatabase, aes(LNfxde))+ geom_line(aes(dateid01, LNfxde), color="blue")
ExchangeratevsPriceindexPlot+geom_line(aes(dateid01, PIratio, color="red"))+ggtitle("Purchasing Power Parity")+xlab("year")+ylab("Exchange Rate/Prices Ratio")+guides(color="none")

adf.test(LNfxde)
##
## Augmented Dickey-Fuller Test
##
## data: LNfxde
## Dickey-Fuller = -1.8015, Lag order = 6, p-value = 0.6597
## alternative hypothesis: stationary
adf.test(PIratio)
##
## Augmented Dickey-Fuller Test
##
## data: PIratio
## Dickey-Fuller = -2.359, Lag order = 6, p-value = 0.4248
## alternative hypothesis: stationary
CointegratinRegression<- lm(LNfxde~PIratio)
summary(CointegratinRegression)
##
## Call:
## lm(formula = LNfxde ~ PIratio)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.35251 -0.06046 0.03119 0.09025 0.25606
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.07192 0.16873 -0.426 0.670
## PIratio 0.40180 0.26291 1.528 0.128
##
## Residual standard error: 0.1355 on 274 degrees of freedom
## Multiple R-squared: 0.008452, Adjusted R-squared: 0.004834
## F-statistic: 2.336 on 1 and 274 DF, p-value: 0.1276
adf.test(residuals(CointegratinRegression))
##
## Augmented Dickey-Fuller Test
##
## data: residuals(CointegratinRegression)
## Dickey-Fuller = -1.7856, Lag order = 6, p-value = 0.6664
## alternative hypothesis: stationary
durbinWatsonTest(residuals(CointegratinRegression))
## [1] 0.04850068