Solution for non-stationarity in time series analysis in STATA

The previous article based on the Dickey Fuller test established that GDP time series data is non-stationary. This prevented time series analysis from proceeding further. Therefore, in this article possible solution to non-stationarity is explained.

First differencing series

If a time series has a unit root problem, the first difference of such time series is ‘stationary’. Therefore, the solution here is to take the first difference of the GDP time series. The first difference of a time series is the series of changes from one period to the next. If Yt denotes the value of the time series Y at period t, then the first difference of Y at period t is equal to Yt-Yt-1. In STATA, the first difference of Y is expressed as DIFF(Y) or D of time series variable. Therefore, to generate the difference between current and previous values use the “D” operator. In the present case, to create a difference of time series GDP:

  1. Click on ‘Data’ (ribbon).
  2. Select ‘Create’ or ‘Change Data’.
  3. Click in ‘Create New Variable’.
  4. Dialogue box will appear as below (Figure 1).

OR

Use STATA command:

generate gap_d1 = d1.gdp

Fill the dialogue box with Variable name ‘gdp_d1’ and specify a value or an expression. Remember for differencing for one time, use prefix ‘d1’. Similarly, when differencing is to be done for second time then use prefix ‘d2’. For instance, the name for variable GDP is given ‘gdp_d1’ and in content of variable option, applied prefix ‘d1 to variable ‘gdp’ for first differencing.

Figure 1: Dialogue box for Creating New Variable

Figure 1: Dialogue box for creating new variable

After clicking ‘OK’  as shown in the figure above, the new variable appears on the Data editor i.e. ‘gdp_d1’ as differencing of variable ‘gdp’. The figure below shows the resulting window.

Figure 2: New variable “gdp_d1” as differencing of variable GDP

Figure 2: New variable ‘gdp_d1’ as differencing of variable GDP

Thus first order differencing of time series variable GDP has been made. Now check again if it is stationary or not. In order to do so, perform both graphical and Dickey Fuller test. The procedure to construct the graph is explained in the previous article.

Graphical representation

The figure below shows that the variable ‘gdp_d1’ is still reflecting an upward trend. However, the trend decreases when compared to original GDP variable. Therefore, GDP time series has been diminished to around zero. This implies that this time series can have a constant mean and variance. However, a mere graphical representation is an intuitive step thus, perform the formal tests of stationarity.

Figure 3: Graphical Representation of 1st differencing of GDP time series

Figure 3: Graphical representation of first differencing of GDP

Dickey Fuller test

As mentioned previously, Dickey Fuller test is conducted to examine stationarity in time series data. To examine the stationarity of differenced GDP time series, follow the steps mentioned in previous article:

  1. Click on ‘Statistics’ (in ribbon of Output Window).
  2. Select ‘Time Series’.
  3. Select ‘Tests’.
  4. Select ‘Augmented Dicky Fuller Test’.

OR

Use STATA Command:

dfuller gap_d1, trend lags(0)

Based on the equation entered, a dialogue box will appear as shown in the figure below. Select the variable ‘gdp_d1’ in ‘Variable’ option, mark on ‘Include trend term in regression’. Click on ‘OK’.

Figure 4: Dialogue Box for Augmented Dickey Fuller Unit root Test

Figure 4: Augmented Dickey Fuller unit root test in STATA

The results for Dickey Fuller test for gdp_d1 will appear in output window. The figure below reflects the results of the Dickey Fuller test of stationarity.

Figure 5: Dickey Fuller test results in STATA

Figure 5: Dickey Fuller test results in STATA

The output window of STATA reflects on the Dickey Fuller test results for variable ‘gdp_d1’. To examine the presence of stationarity, review two value; ‘Z(t)’ and Mackinnon p-value for ‘Z(t)’. Here it can be seen that, ‘Z(t)’ value is -7.073 which is a large negative number (as compared to ‘z(t)’ for ‘gdp’) and p-value is also found significant. Thus, null hypothesis of Dickey Fuller test is rejected.  Therefore,  the first differenced time series GDP is stationary.

Optional: Check the stationarity by taking lags as done in previous article.

Second differencing series

There can be cases when the first differencing of such time series also turns out as non-stationary. Therefore, the solution here is to take the second difference of the GDP time series. In STATA, the second difference of ‘Y’ is expressed as ‘D2(Y)’. Similar to the above case, second differencing of GDP can be calculated as:

  1. Click on ‘Data’ (ribbon).
  2. Select ‘Create’ or ‘Change Data’.
  3. Click in ‘Create New Variable’.
  4. Dialogue box will appear as shown below.

OR

Use STATA command:

 generate gap_d2 = d2.gdp

Fill the below dialogue box with variable name ‘gdp_d2’ and specify a value or an expression. For differencing for second time, use prefix ‘d2’. For instance, the variable has been named as ‘gdp_d2’ and in content of variable option, applied prefix ‘d2’ for second differencing.

Figure 6: Dialogue box for creating a new variable

Figure 6: Dialogue box for creating a new variable

After clicking ‘OK’ as shown in the above figure, check the ‘Data Editor’ window for new variable ‘gdp_d2’ as second differencing of variable ‘gdp’. This is shown in the figure below.

Figure 7: New variable “gdp_d2” as differencing of variable GDP

Figure 7: New variable ‘gdp_d2’ as differencing of variable GDP

After performing second order differencing of time series variable GDP, test if it is stationary or not. Check this with the graph as well as Dickey Fuller test.

Graphical representation

As the figure below shows, ‘gdp_d2’ is not reflecting a upward trend anymore. Thus, GDP time series data has been diminished to around zero. This implies that this time series definitely has a constant mean and variance. Further, to prove this point, perform the Dickey Fuller test to test stationarity.

Figure 8: Graphical representation of second differencing of GDP time series

Figure 8: Graphical representation of second differencing of GDP

Dickey Fuller test

To examine the stationarity of second differenced GDP time series, again follow the steps mentioned in previous article.

  1. Click on ‘Statistics’ (in ribbon of Output Window).
  2. Select ‘Time Series’.
  3. Select ‘Tests’.
  4. Select ‘Augmented Dicky Fuller Test’.

OR

Use STATA Command:

dfuller gap_d2, trend lags(0)

In the dialog box below, select the variable ‘gdp_d2’ in ‘Variable’ option, select ‘Include trend term in regression’. Click on ‘OK’. The results for Dickey Fuller test for ‘gdp_d2’ will appear in output window.

"<yoastmark

Figure 9: Dialogue box for Augmented Dickey Fuller unit root test

 

The figure below shows the results of the unit root test.

Figure 10: Augmented Dickey Fuller unit root test results

Based on the previous interpretations, reviewing the ‘Z(t)’ and Mackinnon p-value for ‘Z(t)’, it can be stated that ‘Z(t)’ value is a large negative number (as compared to ‘z(t)’ for ‘gdp’ and ‘gdp_d1’) and p-value for the same is also significant. Therefore, the null hypothesis is rejected.

Further time series analyses in STATA

This article explained the procedure to remove non-stationarity from time series data. It also tested the data using graphical representation and Dickey Fuller Unit Root test. The next article discusses about the concept of ARIMA and how to process it in STATA.

Priya Chetty

Partner at Project Guru
Priya Chetty writes frequently about advertising, media, marketing and finance. In addition to posting daily to Project Guru Knowledge Tank, she is currently in the editorial board of Research & Analysis wing of Project Guru. She emphasizes more on refined content for Project Guru's various paid services. She has also reviewed about various insights of the social insider by writing articles about what social media means for the media and marketing industries. She has also worked in outdoor media agencies like MPG and hotel marketing companies like CarePlus.

Related articles

  • ARIMA modeling for time series analysis in STATA In the previous article, all possibilities for performing Autoregressive Integrated Moving Average (ARIMA) modeling for the time series GDP were identified as under. S. […]
  • Building univariate ARIMA model for time series analysis in STATA Autoregressive Integrated Moving Average (ARIMA) is popularly known as Box-Jenkins method. The emphasis of this method is on analyzing the probabilistic or stochastic properties of a single time series. Unlike regression models where Y is explained by X1 X2….XN regressor (like […]
  • Problem of non-stationarity in time series analysis in STATA The purpose of this article is to explain the process of determining and creating stationarity in time series analysis. Creating a visual plot of data is the first step in time series analysis. Graphical representation of data helps understand it better.
  • Setting the ‘Time variable’ for time series analysis in STATA Time series analysis works on all structures of data. It comprises of methods to extract meaningful statistics and characteristics of data. Time series test is applicable on datasets arranged periodically (yearly, quarterly, weekly or daily).
  • Prediction and forecasting using ARIMA in STATA After performing Autoregressive Integrated Moving Average (ARIMA) modelling in the previous article: ARIMA modeling for time series analysis in STATA, the time series GDP can be modelled through ARIMA (9, 2, 1) .
Discussions

3 Comments.

  1. Hi! Priya. Thank you For this article which is of great use. Besides, I would like to know why you applied a second differenced to the serie while the Dickey Fuller test said it was stationary. Thanks

    • The second differencing has been done just to show how to do it in STATA, that is for demonstrating the required steps. Since GDP series turned out to be stationary at the first difference, there is no need to check for stationarity at second differences. But we often encounter time series data for variables which remain non stationary even after first differencing. In those cases, we need to proceed one step further and perform Dickey-Fuller test after differencing the data series at the first difference

Discuss

We are looking for candidates who have completed their master's degree or Ph.D. Click here to know more about our vacancies.