Hatemi code for cointegration with multiple structural breaks
This week's blog brings you the second video in the series examining running publicly available GAUSS code. This video runs the popular code by Hatemi-J for testing cointegration with multiple structural breaks. In this video you will learn how to:
- Substitute your own dataset.
- Modify the indexing commands for your data.
- Remove missing values.
- Preview your data after loading with the Ctrl+E keyboard shortcut.
Hello and welcome to the second part of our series on running publicly available GAUSS code. Last time we showed how to set up a project folder, run a program and resolve the
library not found and
file not found errors.
Today we will run the code which implements the tests for cointegration with two unknown structural breaks from Dr. Hatemi’s 2008 paper in Empirical Economics, using a couple of variables from the famous Nelson-Plosser dataset.
We have saved the program and data in a folder named Hatemi under the GAUSS-Projects folder which we created in the first video in this series. If you are not sure how to do that, go back and take a look at the first video.
Let’s start by looking at how this file is laid out. It is split into two main sections. The first part of the file, up to line 22, is responsible for loading data and calling the main procedure, which is in this case literally called main. This is the section that we will need to modify.
This second section of the code contains all of the procedures that Dr. Hatemi wrote to compute the algorithm from his paper.
end command on line 22 is the line of demarcation between these two sections.
GAUSS will not run any commands located after
end, but it will still find the procedures so they will be available for use by the code in the first section.
Data loading code
Let’s look at this first section to see what it is doing. The action starts on line 9 with the
This statement is going to:
- Look for a file named
b22.txtin your current working directory.
- Load the data it finds in that fil.
- Reshape the data to be a matrix with
We’re going to have to change this line because our data is not in
b22.txt and we don’t want to have to specify the data size ahead of time, as we see here with
Our data is in a Stata dataset named
loadd command allows us to load data from many different types of datasets, including Stata datasets and to specify the model variables by name. So we will use
Before we load our data, let’s get a preview of our dataset by double-clicking it in the Project Folder’s Window. Let’s scroll to the right to see all of the variables.
The yellow cells with dots contain missing values. We will deal with those after loading the data.
For this video our dependent variable will be bond yield which is the
bnd variable and our independent variable will be the money supply, which is just
Load, preview and index our data
Let’s use the ‘loadd’ command to load our two variables into ‘z’. (add call-out showing viewers where to get more information about ‘loadd’.)
Now we see that lines 10 and 11 are splitting up the variables that we loaded from our dataset.
The intention of line 10 is to select all observations from the first column of
z. However, we have a problem because
obs has not yet been given a value. We could add a line setting ‘obs’ to be equal to the rows of
z. That would be correct.
However, we can replace
1:obs with the dot operator. This is shorter and makes it clear that our intention is to load all the rows.
We see the same problem in line 11 with the row range and also with the column range. For now, we can just change the column index to two, because
z will only have two columns.
The remaining lines create two variables,
n which do not seem to be used and then there is the call to main. We see that the only variables passed into
x which we have created.
Let’s add an
end command just before the call to
main and then run our code so we can verify that our data is loaded correctly.
x in floating symbol editors by clicking on them and using the
Remove missing values
As we mentioned earlier, the dots represent missing values. The code won’t work if the data contains missing values, so we will have to remove them.
packr command removes all rows in which any element contains a missing value. If we add
packr right after we load the data, the first 40 rows should be trimmed off, leaving us with
z as a
Run the code and view output
Now that we have confirmed that our data is correct, let’s remove the ‘end’ command that we added and run the full code.
We have successfully run the code. Here is our output.
Thank you for watching! I hope this has helped you to become more familiar with GAUSS. Let us know what content you would like to see. Please post your comments and questions below!
Abdulnasser Hatemi-J, (2008), Tests for cointegration with two unknown regime shifts with an application to financial market integration, Empirical Economics, Springer, vol. 35(3), p. 497-505.
Nelson, Charles and Plosser, Charles, (1982), Trends and random walks in macroeconmic time series: Some evidence and implications, Journal of Monetary Economics, vol. 10(2), p. 139-162.