Correcting for stationarity in time series
In the previous recipe, we have learned how to investigate if a given time series is stationary. In this one, we investigate how to make a non-stationary time series stationary by using one (or multiple) of the following transformations:
- deflation - accounting for inflation in monetary series using the Consumer Price Index (CPI)
- applying the natural logarithm - making the potential exponential trend closer to linear and reducing the variance of the time series
- differencing - taking the difference between the current observation and a lagged value (observation x time points before it)
For this exercise, we use monthly gold prices from the years 2000 to 2010. We have chosen this sample on purpose, as over that period the price of gold exhibits a consistently increasing trend - the series is definitely not stationary.
How to do it...
Execute the following steps to transform the series from non-stationary to stationary.
- Import the libraries...