Handling unit root problem from Dickey-Fuller test in time series analysis
The previous article based on the Dickey-Fuller test established that GDP time series data is non-stationary. This prevented the 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 the 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:
- Click on ‘Data’ (ribbon).
- Select ‘Create’ or ‘Change Data’.
- Click on ‘Create New Variable’.
- The dialogue box will appear below (Figure 1).
OR
Use the STATA command:
generate gap_d1 = d1.gdp
Fill the dialogue box with the Variable name ‘gdp_d1’ and specify a value or an expression. Remember for differencing for one time, use the prefix ‘d1’. Similarly, when differencing is to be done for a second time then use the prefix ‘d2’. For instance, the name for variable GDP is given ‘gdp_d1’ and in the content of variable option, applied prefix ‘d1 to the variable ‘gdp’ for first differencing.

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

Thus first-order differencing of the time series variable ‘gdp’ has been made. Now check again if it is stationary or not. To do so, perform both graphical and Dickey-Fuller tests. 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 the original GDP variable. Therefore, the 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, performing the formal tests of stationarity.

Dickey-Fuller test
As mentioned previously, the Dickey-Fuller test is conducted to examine stationarity in time series data. To examine the stationarity of different GDP time series, follow the steps mentioned in the previous article:
- Click on ‘Statistics’ (in the ribbon of the Output Window).
- Select ‘Time Series’.
- Select ‘Tests’.
- 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 the ‘Variable’ option, and mark on ‘Include trend term in regression’. Click on ‘OK’.

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

The output window of STATA reflects on the Dickey-Fuller test results for variable ‘gdp_d1’. To examine the presence of stationarity, review two values; ‘Z(t)’ and Mackinnon p-value for ‘Z(t)’. Here it can be seen that the ‘Z(t)’ value is -7.073 which is a large negative number (as compared to ‘z(t)’ for ‘gdp’) and the p-value is also found significant. Thus, the null hypothesis of the Dickey-Fuller test is rejected. Therefore, the first differenced time series GDP is stationary.
Check the stationarity by taking lags as done in the 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 in the GDP time series. In STATA, the second difference of ‘Y’ is expressed as ‘D2(Y)’. Similar to the above case, the second differencing of GDP can be calculated as:
- Click on ‘Data’ (ribbon).
- Select ‘Create’ or ‘Change Data’.
- Click on ‘Create New Variable’.
- The dialogue box will appear as shown below.
OR
Use the STATA command:
generate gap_d2 = d2.gdp
Fill the below dialogue box with the variable name ‘gdp_d2’ and specify a value or an expression. For differencing for a second time, use the prefix ‘d2’. For instance, the variable has been named as ‘gdp_d2’ and in the content of the variable option, applied prefix ‘d2’ for second differencing.

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

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 the Dickey-Fuller test.
Graphical representation
As the figure below shows, ‘gdp_d2’ is not reflecting an upward trend anymore. Thus, GDP time series data has been diminished to around zero. This implies that this time series has a constant mean and variance. Further, to prove this point, perform the Dickey-Fuller test to test stationarity.

Dickey-Fuller test
To examine the stationarity of the second differenced GDP time series, again follow the steps mentioned in the previous article.
- Click on ‘Statistics’ (in a ribbon of the Output Window).
- Select ‘Time Series’.
- Select ‘Tests’.
- Select ‘Augmented Dicky Fuller Test’.
OR
Use STATA Command:
dfuller gap_d2, trend lags(0)
In the dialogue box below, select the variable ‘gdp_d2’ in the ‘Variable’ option, and select ‘Include trend term in regression’. Click on ‘OK’. The results for the Dickey-Fuller test for ‘gdp_d2’ will appear in the output window.

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 the ‘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 the Dickey-Fuller Unit Root Test. The next article discusses the concept of ARIMA and how to process it in STATA.
Discuss