This is the companion notebook to the course on Time-series analysis. The dataset consists of 3 series of indicators characterising the French economy.

library(tidyverse)
# Then change your working directory
if(!require(lubridate)){install.packages("lubridate")}
library(lubridate)
load("economics.RData")
summary(economics)  # Descriptive statistics
    Quarter            GDP          Unemployment        CPI        
 Min.   :199001   Min.   :261484   Min.   : 6.80   Min.   : 66.56  
 1st Qu.:199701   1st Qu.:318372   1st Qu.: 8.10   1st Qu.: 77.47  
 Median :200401   Median :421974   Median : 8.90   Median : 85.59  
 Mean   :200365   Mean   :419099   Mean   : 8.91   Mean   : 85.92  
 3rd Qu.:201101   3rd Qu.:511961   3rd Qu.: 9.80   3rd Qu.: 95.67  
 Max.   :201801   Max.   :582503   Max.   :10.40   Max.   :101.72  
economics <- mutate(economics, Year = as.numeric(substr(Quarter,1,4)), Quarter = as.numeric(substr(Quarter,5,6)))
economics <- mutate(economics, Date = make_date(year = Year, month = 3*Quarter, day = 1))

First analysis

The first thing to do is often to have a look at the data:

eco <- economics %>% select(-Year, -Quarter) %>% gather(key = Variable, value = Value, -Date) 
ggplot(eco, aes(x = Date, y = Value)) + geom_line() + facet_grid(Variable ~ .,  scales = 'free')

Obviously, these series are not stationary (at least the first two), if only because of their trend which implies that their mean increases with time (the range of the distribution is clearly not constant). One possible solution is to study variations: \[\Delta X_t = X_t-X_{t-1}\]

economics <- economics %>% mutate(GDP_var = GDP - lag(GDP))    # Raw variation in GDP
ggplot(economics, aes(x = Date, y = GDP_var)) + geom_point()

Clearly, this is better. Indeed, it seems that the variations in the French GDP display a somewhat coherent pattern. Nevertheless, the classical transform used to `stationarise’ series consists in computing growth, i.e., relative variations: \[r_t=\frac{X_t}{X_{t-1}}-1\] I use the notation r because in finance, these series are called ‘returns’. Henceforth, I will often use this abuse of language.

economics <- economics %>% mutate(GDP_growth = GDP / lag(GDP) - 1) # Growth in GDP
ggplot(economics, aes(x = Date, y = GDP_growth)) + geom_bar(stat = "identity")