Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: THEend8_
This practical session explores the dynamic relationship between gold and silver prices, focusing on unit root tests, spurious regressions, and Granger causality.
1 Load the Data
We will analyse the ‘GoldSilver’ dataset from the ‘AER ’ library, comprising daily spot prices for gold (per 0.1 oz) and silver (per 10 oz) from December 30, 1977, to December 31, 2012. This multivariate dataset provides a rich basis for our exploration.
To load this dataset into R, execute the following commands:
library(AER)
data("GoldSilver")
1.1 Data Preparation
The data preparation involves log transforming the series to stabilise variance and compress the scale of the data. This approach mitigates the disparity between small and large values, ensuring a more meaningful analysis. Furthermore, considering the extensive span of the dataset and to focus our investigation on more recent trends and dynamics between gold and silver prices, we concentrate on a subset of the data post-1990 using the ‘window’ function.
Execute the following R code to prepare the data:
lgs <- log(GoldSilver)
lgs78 <- window(lgs, start = as.Date("1990-01-01"))
gold <- lgs78[,1]
silver <- lgs78[,2]
The final two lines of code precisely extract the ‘gold’ and ‘silver’ series from the adjusted multivariate dataset ‘lgs78’, ensuring that our analysis is targeted and relevant.
2 Loading the Required Packages
To effectively carry out our analysis, we will use several R packages for dynamic linear modelling and hypothesis testing. Load the necessary packages into your R session as follows:
library(dynlm)
library(car)
This enables the use of ‘dynlm()’ for dynamic modelling and ‘linearHypothesis()’ for performing F-tests, among other analytical capabilities.
3 Analysis of Gold and Silver Prices
This exercise focuses on the dynamic relationship between gold and silver prices, with a focus on unit root tests, the detection of spurious regressions, and the understanding of Granger causality. Our objective is to interpret the results of statistical tests to gain insights into the properties of the time series data and their relationship.
3.1 Testing for Unit Roots
Determining whether the gold and silver price series are integrated — that is, if they contain unit roots — is our first analytical step. This is crucial for understanding the time series’ characteristics and selecting the appropriate modelling techniques.
1. Visual Inspection:
Start by closely examining the plot of the log-transformed prices. Observe and discuss any discernible patterns, and compare the two series with respect to their volatility and trends. This initial visual inspection is an essential preliminary step for gaining insight into the underlying behaviour of the series.