# 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 Y_{t} denotes the value of the time series Y at period t, then the first difference of Y at period t is equal to Y_{t}-Y_{t-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:

- Click on ‘Data’ (ribbon).
- Select ‘Create’ or ‘Change Data’.
- Click in ‘Create New Variable’.
- 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.

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.

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.

**5E25A5EE63214**to save 5000 on

**15001 - 20000 words**standard order of

**literature survey**service.

^{}### 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:

- Click on ‘Statistics’ (in ribbon of 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 ‘Variable’ option, mark on ‘Include trend term in regression’. Click on ‘OK’.

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.

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:

- Click on ‘Data’ (ribbon).
- Select ‘Create’ or ‘Change Data’.
- Click in ‘Create New Variable’.
- 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.

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.

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.

### Dickey Fuller test

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

- Click on ‘Statistics’ (in ribbon of Output Window).
- Select ‘Time Series’.
- Select ‘Tests’.
- 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.

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.

**5E3BCCB908B47**to save 6000 on

**6001 - 10000 words**standard order of

**research analysis**service.

^{}## 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.

- Different types of structural equation modelling analysis - October 20, 2021
- How to review the literature to effectively address the problem statement and objectives of a thesis? - October 15, 2021
- Understanding the foundations of structural equation modeling - October 14, 2021

## Discuss