Unit Root Test - Time Series


In this section, you will learn to carry out the unit root tests on time series data (Dickey-Fuller, PP, KPSS, and others) in STATA. We will explain in detail about them in the following steps:


Step 1: Upload the MS-Excel datasheet in STATA


Let us assume, the name of the MS-Excel datasheet is "Time-Series-Data-Representation.xlsx" and it is located in the path "D:\data\". Then the data upload command in STATA is given by:

import excel "D:\data\Time-Series-Data-Representation.xlsx", sheet("DATA") firstrow

Now click ENTER. Your data is uploaded in STATA.



Step 2: Define the data as time series data in STATA

Once the data is uploaded in STATA, we need to define the data to be time series data. For that purpose, we need to declare the time-series ids in the data. Then the data declaration command in STATA is given by:

tsset YEAR

Once you click ENTER, you will get the following:

time variable: YEAR, 1971 to 2010
delta: 1 unit


Now your data is declared in STATA.



Step 3: Run the unit root test(s) on level data in STATA


Once the data is declared in STATA, you can run the unit root tests. In the dataset, there are three variables (EC, CE, and GDP).

Now, let us assume, you want to test the Dickey-Fuller unit root for the variable EC at the level. Then the command in STATA is given by:

dfuller EC

Once you click ENTER, you will get the following:



Now, please note that you can adjust the lag length according to your convenience and requirement of the study by adding
lags(1) in the command. One thing you need to notice here, that the results are indicating the presence of unit root in EC (look at the MacKinnon approximate p-value for Z(t) below). For reporting purpose, you can consider the Test Statistic.

Now, let us assume, you want to test the PP unit root for the variable EC at the level. Then the command in STATA is given by:

pperron EC

Once you click ENTER, you will get the following:



Now, please note that you can adjust the lag length according to your convenience and requirement of the study by adding
lags(1) in the command. One thing you need to notice here, that the results are indicating the presence of unit root in EC (look at the MacKinnon approximate p-value for Z(t) below). For reporting purpose, you can consider the Test Statistic) for Z(t).

Now, let us assume, you want to test the KPSS unit root for the variable EC at the level. Then the command in STATA is given by:

kpss EC

Once you click ENTER, you will get the following:



Now, please note that you can adjust the lag length according to your convenience and requirement of the study by adding
lags(1) in the command. One thing you need to notice here, that the results are indicating the presence of unit root in EC (look at the Test Statistic, which are higher than the values at different significance levels). For reporting purpose, you can consider the Test Statistic for lag(0).


Step 4: Run the unit root test(s) on first difference data in STATA


By far, we have tested that the variable EC has unit root at the level. Now, we need to check, whether this variable contains unit root after first difference, or not. For most of the statistical analysis techniques involving unit root tests, it is required that the variables should be stationary at least after first difference. For that purpose, first we need to differentiate the variable, and we will store the differentiated values in a new variable, named DEC. Then the command in STATA is given by:

generate DEC=EC-EC[_n-1]

Once you click ENTER, you will get the following:

(1 missing value generated)

Now that we have generated the differentiated variable, we can now proceed with the unit root tests, just like we have just mentioned. So, let us start with the Dickey-Fuller test. The command in STATA is given by:

dfuller DEC

Once you click ENTER, you will get the following:



Now, please note that you can adjust the lag length according to your convenience and requirement of the study by adding
lags(1) in the command. One thing you need to notice here, that the results are indicating that the unit roots are removed from EC at 5% significance level (look at the MacKinnon approximate p-value for Z(t) below). For reporting purpose, you can consider the Test Statistic.

Now, we will apply the PP unit root for the variable DEC. The command in STATA is given by:

pperron DEC

Once you click ENTER, you will get the following:



Now, please note that you can adjust the lag length according to your convenience and requirement of the study by adding
lags(1) in the command. One thing you need to notice here, that the results are indicating that the unit roots are removed from EC at 5% significance level (look at the MacKinnon approximate p-value for Z(t) below). For reporting purpose, you can consider the Test Statistic) for Z(t).

Now, we will apply the KPSS unit root for the variable DEC. The command in STATA is given by:

kpss DEC

Once you click ENTER, you will get the following:



Now, please note that you can adjust the lag length according to your convenience and requirement of the study by adding
lags(1) in the command. One thing you need to notice here, that the results are indicating that the unit roots are removed from EC (look at the Test Statistic values, which are between the values at different significance levels). For reporting purpose, you can consider the Test Statistic for lag(0).

Following these steps, you can easily carry out the unit root tests for time series in STATA. For more information on these tests, please give the following commands respectively in STATA:

help dfuller

help pperron

help kpss

If these commands are not installed in STATA, then you will have use the following commands respectively in STATA to find and install the codes:

findit dfuller

findit pperron

findit kpss


Go Backfast_rewind
add