<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>cointegration &#8211; Aptech</title>
	<atom:link href="https://www.aptech.com/blog/tag/cointegration/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.aptech.com</link>
	<description>GAUSS Software - Fastest Platform for Data Analytics</description>
	<lastBuildDate>Mon, 10 Mar 2025 17:05:47 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	
	<item>
		<title>How to Interpret Cointegration Test Results</title>
		<link>https://www.aptech.com/blog/how-to-interpret-cointegration-test-results/</link>
					<comments>https://www.aptech.com/blog/how-to-interpret-cointegration-test-results/#comments</comments>
		
		<dc:creator><![CDATA[Eric]]></dc:creator>
		<pubDate>Tue, 26 May 2020 20:36:06 +0000</pubDate>
				<category><![CDATA[Time Series]]></category>
		<category><![CDATA[cointegration]]></category>
		<category><![CDATA[unit root]]></category>
		<guid isPermaLink="false">https://www.aptech.com/?p=22067</guid>

					<description><![CDATA[In this blog, we will explore how to set up and interpret cointegration results using a real-world time series example. We will cover the case with no structural breaks as well as the case with one unknown structural break using tools from the GAUSS tspdlib library.
]]></description>
										<content:encoded><![CDATA[<h3 id="introduction">Introduction</h3>
<p>In this blog we will explore how to <strong>set up and interpret cointegration results</strong> using a real-world time series example. We will cover the case with <strong>no structural breaks</strong> as well as the case with <strong>one unknown structural break</strong> using tools from the GAUSS <a href="https://github.com/aptech/tspdlib">tspdlib library</a>.</p>
<h2 id="dataset">Dataset</h2>
<p>In this blog, we will use the famous <a href="https://github.com/aptech/tspdlib/blob/master/examples/nelsonplosser.dta">Nelson-Plosser time series data</a>. The dataset contains macroeconomic fundamentals for the United States.</p>
<p>We will be using three of these fundamentals:</p>
<ul>
<li>M2 money stock.</li>
<li>Bond yield (measured by the basic yields of 30-year corporate bonds).</li>
<li>S&amp;P 500 index stock prices.</li>
</ul>
<p>The <a href="https://www.aptech.com/blog/introduction-to-the-fundamentals-of-time-series-data-and-analysis/">time series data</a> is annual data, covering 1900 - 1970.</p>
<h2 id="preparing-for-cointegration">Preparing for Cointegration</h2>
<p>In order to prepare for <a href="https://www.aptech.com/blog/a-guide-to-conducting-cointegration-tests/">cointegration testing</a>, we will take some preliminary time series modeling steps. We will:</p>
<ul>
<li><a href="https://www.aptech.com/blog/a-guide-to-conducting-cointegration-tests/#establishing-underlying-theory">Establish our underlying theory</a>.</li>
<li><a href="https://www.aptech.com/blog/a-guide-to-conducting-cointegration-tests/#time-series-visualization">Visualize our time series data</a>.</li>
<li><a href="https://www.aptech.com/blog/a-guide-to-conducting-cointegration-tests/#unit-root-testing">Perform unit root testing</a>. </li>
</ul>
<h3 id="establishing-an-underlying-theory">Establishing an Underlying Theory</h3>
<p>In this example, we will examine the macroeconomic question of whether stock prices are linked to macroeconomic indicators. In particular, we will examine if there is a cointegrated, long-run relationship between the S&amp;P 500 price index and monetary policy indicators of the M2 money stock and the bond yields. </p>
<p>Mathematically we will consider the cointegrated relationship:</p>
<p>$$y_{sp, t} = c + \beta_1 y_{money, t} + \beta_2y_{bond, t} + u_t$$ </p>
<h3 id="time-series-visualization">Time Series Visualization</h3>
<p>When <a href="https://www.aptech.com/resources/tutorials/tsmt/wpi-visualizing-time-series-data/">visualizing time series data</a>, we look for visual evidence of:</p>
<ul>
<li>The comovements between our variables.</li>
<li>The presence of deterministic components such as constants and time trends.</li>
<li>Potential <a href="https://www.aptech.com/structural-breaks/">structural breaks</a>.</li>
</ul>
<p><a href="https://www.aptech.com/wp-content/uploads/2020/05/time-series-plots-sm.jpg"><img src="https://www.aptech.com/wp-content/uploads/2020/05/time-series-plots-sm.jpg" alt="Time series plot to examine cointegration." width="879" height="371" class="aligncenter size-full wp-image-22071" /></a></p>
<p>Our time series plots give us some important considerations for our testing, providing visual evidence to support:</p>
<ol>
<li>Comovements between the variables.</li>
<li>At least one structural break in the time series dynamics of all three of our variables.</li>
<li>A potential time trend in the datasets, especially in the later years of the sample.</li>
</ol>
<h3 id="unit-root-testing">Unit Root Testing</h3>
<p>Prior to testing for cointegration between our time series data, we should check for <a href="https://www.aptech.com/why-gauss-for-unit-root-testing/">unit roots</a> in the data. We will do this using the <code>adf</code> procedure in the <code>tspdlib</code> library to conduct the <a href="https://www.aptech.com/blog/how-to-conduct-unit-root-tests-in-gauss/#the-augmented-dickey-fuller-test">Augmented Dickey-Fuller unit root test</a>. </p>
<table>
 <thead>
<tr><th>Variable</th><th>Test Statistic</th><th>1% Critical Value</th><th>5% Critical Value</th><th>10% Critical Value</th><th>Conclusion</th></tr></thead>
<tbody>
<tr><td><b>Money</b></td><td>1.621</td><td>-4.04</td><td>-3.45</td><td>-3.15</td><td>Cannot reject the null</td></tr>
<tr><td><b>Bond yield</b></td><td>-1.360</td><td>-4.04</td><td>-3.45</td><td>-3.15</td><td>Cannot reject the null</td></tr>
<tr><td><b>S&amp;P 500</b></td><td>-0.3842</td><td>-4.04</td><td>-3.45</td><td>-3.15</td><td>Cannot reject the null</td></tr>
</tbody>
</table>
<p>Our ADF test statistics are greater than the 10% critical value for all of our time series. This implies that we cannot reject the null hypothesis of a unit root for any of our time series data.  </p>
<div class="alert alert-info" role="alert">For detailed information on conducting unit root tests in GAUSS see our previous blog on <a href="https://www.aptech.com/blog/how-to-conduct-unit-root-tests-in-gauss/">“How to Conduct Unit Root Tests in GAUSS”</a>.</div>
<h3 id="unit-root-testing-with-structural-breaks">Unit Root Testing with Structural Breaks</h3>
<p>What about the potential structural break that we see in our time series data? Does this have an impact on our unit root testing? </p>
<p>Using the <code>adf_1break</code> procedure in the <code>tspdlib</code> library to test for <a href="https://www.aptech.com/blog/unit-root-tests-with-structural-breaks/">unit roots with a single structural break</a> in the trend and constant we get the following results. </p>
<table>
 <thead>
<tr><th>Variable</th><th>Test Statistic</th><th>Break Date</th><th>1% Critical Value</th><th>5% Critical Value</th><th>10% Critical Value</th><th>Conclusion</th></tr></thead>
<tbody>
<tr><td><b>Money</b></td><td>-4.844</td><td>1948</td><td>-5.57</td><td>-5.08</td><td>-4.82</td><td>Cannot reject the null</td></tr>
<tr><td><b>Bond yield</b></td><td>-3.226</td><td>1963</td><td>-5.57</td><td>-5.08</td><td>-4.82</td><td>Cannot reject the null</td></tr>
<tr><td><b>S&amp;P 500</b></td><td>-4.639</td><td>1945</td><td>-5.57</td><td>-5.08</td><td>-4.82</td><td>Cannot reject the null</td></tr>
</tbody>
</table>
<p>Our ADF test statistics again suggest that even when accounting for the structural break, we cannot reject the null hypothesis of a unit root for any of our time series data. </p>
<h2 id="conducting-our-cointegration-tests">Conducting our Cointegration Tests</h2>
<p>Having concluded that there is evidence for unit roots in our data, we can now run our cointegration tests. </p>
<p>When setting up cointegration tests, there are a number of assumptions that we must specify:</p>
<ul>
<li>Which normalization we want to use.</li>
<li>The deterministic components to include in our model.</li>
<li>The maximum number of lags to allow in our test.</li>
<li>The information criterion to use to select the optimal number of lags.  </li>
</ul>
<p>To better understand these general assumptions, let’s look at the simplest of our tests, the <a href="https://www.aptech.com/blog/a-guide-to-conducting-cointegration-tests/#the-engle-granger-cointegration-test">Engle-Granger</a> cointegration test.  </p>
<h3 id="normalization">Normalization</h3>
<p>In the two-stage, residual-based cointegration tests which we will consider today, normalization amounts to deciding which variable is our dependent variable and which variables are our independent variables in the cointegration regression. </p>
<p>We will choose our normalization to reflect our theoretical question of whether the S&amp;P 500 index is cointegrated with the money stock and the bond yield. As we mentioned earlier, this means we will consider the cointegrated relationship:</p>
<p>$$y_{sp, t} = c + \beta_1 y_{money, t} + \beta_2 y_{bond, t} + u_t$$ </p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Set fname to name of dataset
fname = "nelsonplosser.dta";

// Load three variables from the dataset 
// and remove rows with missing values
coint_data = packr(loadd(fname, "sp500 + m + bnd"));

// Define y and x matrix
y = coint_data[., 1];
x = coint_data[., 2 3];</code></pre>
<h3 id="the-deterministic-component">The Deterministic Component</h3>
<p>The second assumption we must make about our Engle-Granger test is which <code>model</code> we wish to use. To understand how to make this decision, let's look closer at what this input means. </p>
<p>The Engle-Granger test is a two-step test:</p>
<ul>
<li>Estimate the cointegration regression. </li>
<li>Test for stationary in the residuals using the ADF unit root test. </li>
</ul>
<p>When we specify which model to use we impact two things:</p>
<ol>
<li>The deterministic components which are used in the first-stage cointegration regression.</li>
<li>The distribution of the test statistic. </li>
</ol>
<p>There are three options to choose from:</p>
<ol>
<li>
<p>No constant or trend (<code>model = 0</code>)
$$y_{sp, t} = \beta_1 y_{money, t} + \beta_2 y_{bond, t} + u_t$$ </p>
</li>
<li>
<p>Constant (<code>model = 1</code>)
$$y_{sp, t} = \alpha + \beta_1 y_{money, t} + \beta_2 y_{bond, t} + u_t$$ </p>
</li>
<li>Constant and trend (<code>model = 2</code>)
$$y_{sp, t} = \alpha + \delta t + \beta_1 y_{money, t} + \beta_2 y_{bond, t} + u_t$$ </li>
</ol>
<p>For our example, we will include a constant and trend in our first-stage cointegration regression by setting:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Select model with constant and trend
model = 2;</code></pre>
<h3 id="the-lag-specifications">The Lag Specifications</h3>
<p>In the second-stage ADF residual unit root test, the error terms should be serially independent.  To account for possible autocorrelation, lags of the first differences of the residual can be included in ADF test regression.</p>
<p>The GAUSS <code>coint_egranger</code> will automatically determine the optimal number of lags to include in the second-stage regression based on two user inputs:</p>
<ol>
<li>The maximum number of lags to allow.</li>
<li>The criterion to use to determine the optimal number of lags:
<ul>
<li>The Akaike information criterion (AIC) [<code>ic =  0</code>]</li>
<li>The Schwarz information criterion (SIC) [<code>ic = 1</code>]</li>
<li>The t-stat criterion [<code>ic = 2</code>]</li>
</ul></li>
</ol>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">/*
** Information Criterion: 
** 1=Akaike; 
** 2=Schwarz; 
** 3=t-stat sign.
*/
ic = 2; 

// Maximum number of lags 
pmax = 12;  </code></pre>
<h3 id="calling-our-cointegration-test">Calling our Cointegration Test</h3>
<p>Now that we have loaded our data and chosen the test settings, we can call the <code>coint_egranger</code> procedure:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Perform Engle-Granger Cointegration Test
{ tau_eg, cvADF_eg } = coint_egranger(y, x, model, pmax, ic);</code></pre>
<h2 id="interpreting-our-cointegration-results">Interpreting Our Cointegration Results</h2>
<p>In order to interpret our cointegration results, let's revisit the two steps of the Engle-Granger test:</p>
<ol>
<li>Estimate the cointegration regression.</li>
<li>Test the residuals from the cointegration regression for unit roots. </li>
</ol>
<p>The Engle-Granger test statistic for cointegration reduces to an ADF unit root test of the residuals of the cointegration regression:</p>
<ul>
<li>If the residuals contain a unit root, then there is no cointegration.</li>
<li>The null hypothesis of the ADF test is that the residuals have a unit root. Therefore, the Engle-Granger test considers the null hypothesis that there is no cointegration.</li>
<li>As the Engle-Granger test statistic decreases:
<ul>
<li>We are more likely to reject the null hypothesis of no cointegration.</li>
<li>We have stronger evidence that the variables are cointegrated.</li>
</ul></li>
</ul>
<p>After running our cointegration test we obtain the following results:</p>
<pre>-----------Engle-Granger Test---------------------------
-----------Constant and Trend---------------------------
H0: no co-integration (EG, 1987 &amp; P0, 1990)

     Test      Statistic   CV(1%,      5%,      10%)
   ------      -------------------------------------
   EG_ADF         -2.105   -4.645   -4.157   -3.843
</pre>
<p>We can see that:</p>
<ul>
<li>Our test statistic of -2.105 is larger than the critical values at the 1%, 5%, and 10% levels. </li>
<li>We cannot reject the null hypothesis of no cointegration. </li>
<li>We do not find evidence in support of the cointegration of the S&amp;P 500 with the U.S. money stock and bond yield. </li>
</ul>
<h2 id="conducting-our-cointegration-tests-with-one-structural-break">Conducting our Cointegration Tests with One Structural Break</h2>
<p>Earlier we saw that the potential structural break in our data did not change our unit root test conclusion. We should also see if the structural break has an impact on our cointegration testing.</p>
<p>To do this we will use the Gregory-Hansen cointegration test which can be implemented using the <code>coint_ghansen</code> test in the <code>tspdlib</code> library.</p>
<p>We can carry over all of our <code>coint_egranger</code> testing specifications, except our model specification. </p>
<h3 id="the-model-specification">The Model Specification</h3>
<p>When implementing the Gregory-Hansen test, we must decide on a model which specifies:</p>
<ul>
<li>Which deterministic components are present in the cointegration regression.</li>
<li>How the structural break affects the cointegration regression. </li>
</ul>
<p>There are four modeling options to choose from </p>
<ol>
<li>The level shift [<code>model = 1</code>]<br/><br/>
$$y_{sp, t} = \mu_1(1 - d_{\tau}) + \mu_{1,\tau} d_{\tau} + \beta_1 y_{money, t} + \beta_2 y_{bond, t} + u_t$$<br/>
In this model, there is a structural break at time $\tau$ and $d_{\tau}$ is an indicator variable equal to 1 when $t >= \tau$. The constant before the structural break is $\mu_1$ and the constant after the structural break is $\mu_2$.<br/><br/></li>
<li>The level shift with trend [<code>model = 2</code>]<br/><br/>
$$y_{sp, t} = \mu_1(1 - d_{\tau}) + \mu_{1,\tau} d_{\tau} + \delta t + \beta_1 y_{money, t} + \beta_2 y_{bond, t} + u_t$$<br/>
In this model, the structural break again affects the constant. However, there is also a time trend included in the model.<br/><br/></li>
<li>The regime shift [<code>model = 3</code>]<br/><br/>
$$y_{sp, t} = \mu_1(1 - d_{\tau}) + \mu_{1,\tau} d_{\tau} + \beta_1(1 - d_{\tau})y_{money, t} +$$ $$\beta_{1,\tau}d_{\tau}y_{money, t} + \beta_2(1 - d_{\tau}) y_{bond, t} + \beta_{2,\tau}d_{\tau}y_{bond, t} + u_t$$<br/>
In this model, the structural break affects the constant and regression coefficients.<br/><br/></li>
<li>The regime and trend shift shift [<code>model = 4</code>]<br/><br/>
$$y_{sp, t} = \mu_1(1 - d_{\tau}) + \mu_{1,\tau} d_{\tau} + \delta_1(1 - d_{\tau}) t + \delta_{1,\tau}d_{\tau}t + \beta_1(1 - d_{\tau})y_{money, t} +$$ $$\beta_{1,\tau}d_{\tau}y_{money, t} + \beta_2(1 - d_{\tau}) y_{bond, t} + \beta_{2,\tau}d_{\tau}y_{bond, t} + u_t$$</li>
</ol>
<p>In this model, the structural break again affects the constant, the regression coefficients, and the trend.</p>
<p>For example, let's consider the last case, where the constant, coefficients, and trend are all impacted by the structural break:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Set fname to name of dataset
fname = "nelsonplosser.dta";

// Load three variables from the dataset
// and remove rows with missing values
coint_data = packr(loadd(fname, "sp500 + m + bnd"));

// Define y and x matrix
y = coint_data[., 1];
x = coint_data[., 2 3];

// Regime and trend shift
model = 4; 

/*
** Information Criterion: 
** 1=Akaike; 
** 2=Schwarz; 
** 3=t-stat sign.
*/
ic = 2; 

// Maximum number of lags 
pmax = 12;  

/*
** Long run variance computation
** 1 = iid
** 2 = Bartlett
** 3 = Quadratic Spectral (QS);
** 4 = SPC with Bartlett /see (Sul, Phillips &amp; Choi, 2005)
** 5 = SPC with QS;
** 6 = Kurozumi with Bartlett
** 7 = Kurozumi with QS
*/ 
varm = 1;

// Bandwidth for variance 
bwl=1;

// Data trimming
trimm=0.1;

// Perform cointegration test
{ ADF_min_gh, TBadf_gh, Zt_min_gh, TBzt_gh, Za_min_gh, TBza_gh, cvADFZt_gh, cvZa_gh } =
    coint_ghansen(y, x, model, bwl, ic, pmax, varm, trimm);</code></pre>
<h2 id="interpreting-our-cointegration-results-with-one-structural-break">Interpreting Our Cointegration Results with One Structural Break</h2>
<p>The <code>coint_ghansen</code> procedure provides more extensive results than the <code>coint_egranger</code> test. In particular, the <a href="https://www.aptech.com/blog/a-guide-to-conducting-cointegration-tests/#testing-for-cointegration-with-structural-breaks">Gregory-Hansen test</a>:</p>
<ul>
<li>Performs Augmented Dickey-Fuller testing on the residuals from the cointegration regression. </li>
<li>Perform the <a href="https://www.aptech.com/blog/how-to-conduct-unit-root-tests-in-gauss/#the-phillips-perron-test">Phillips-Perron testing</a> on the residuals from the cointegration regression. </li>
<li>Identifies structural breaks. </li>
</ul>
<h3 id="cointegration-results-with-one-structural-break">Cointegration results with one structural break</h3>
<p><b>Cointegration test results</b><br />
After calling the <code>coint_ghansen</code> procedure and testing all possible models, we obtain the following test statistic results:</p>
<table>
<thead>
<tr><th>Test</th><th>$ADF$ Test Statistic</th><th>$Z_t$ Test Statistic</th><th>$Z_{\alpha}$ Test Statistic</th><th>10% Critical Value $ADF$,$Z_t$</th><th>10% Critical Value $Z_{\alpha}$</th><th>Conclusion</th></tr>
</thead>
<tbody>
<tr><td><b>Gregory-Hansen, Level shift</b></td><td>-4.004</td><td>-3.819</td><td>-27.858</td><td>-4.690</td><td>-42.490</td><td>Cannot reject the null of no cointegration for $ADF$, $Z_t$, or $Z_{\alpha}$.</td></tr>
<tr><td><b>Gregory-Hansen, Level shift with trend</b></td><td>-3.889</td><td>-3.751</td><td>-27.618</td><td>-5.030</td><td>-48.94</td><td>Cannot reject the null of no cointegration for $ADF$, $Z_t$, or $Z_{\alpha}$.</td></tr>
<tr><td><b>Gregory-Hansen, Regime change</b></td><td>-4.658</td><td>-4.539</td><td>-32.766</td><td>-5.23</td><td>-52.85</td><td>Cannot reject the null of no cointegration for $ADF$, $Z_t$, or $Z_{\alpha}$.</td></tr>
<tr><td><b>Gregory-Hansen, Regime change with trend</b></td><td>-5.834</td><td>-4.484</td><td>-32.411</td><td>-5.72</td><td>-63.10</td><td>Cannot reject the null of no cointegration for  $ADF$, $Z_t$, or $Z_{\alpha}$.</td></tr>
</tbody>
</table>
<p>As we can see from these results, there is no evidence that our S&amp;P 500 Index is cointegrated with the money stock and bond yield. </p>
<p><b>Structural break results</b><br />
The <code>coint_ghansen</code> procedure also returns estimates for break dates based on the $ADF$, $Z_t$, and $Z_{\alpha}$ tests:</p>
<table>
<thead>
<tr><th>Test</th><th>$ADF$ Break Date</th><th>$Z_t$ Break Date</th><th>$Z_{\alpha}$ Break Date</th></tr>
</thead>
<tbody>
<tr><td><b>Gregory-Hansen, Level shift</b></td><td>1958</td><td>1956</td><td>1956</td></tr>
<tr><td><b>Gregory-Hansen, Level shift with trend</b></td><td>1958</td><td>1956</td><td>1956</td></tr>
<tr><td><b>Gregory-Hansen, Regime change</b></td><td>1955</td><td>1955</td><td>1955</td></tr>
<tr><td><b>Gregory-Hansen, Regime change with trend</b></td><td>1951</td><td>1953</td><td>1947</td></tr>
</tbody>
</table>
<h3 id="what-can-we-conclude-from-the-gregory-hansen-cointegration-test">What can we Conclude from the Gregory-Hansen Cointegration Test?</h3>
<p>The results from our Gregory Hansen cointegration test provide some important conclusions:</p>
<ul>
<li>There is no support for cointegration.</li>
<li>Incorporating a structural break does NOT change our conclusion that there is no cointegration. </li>
</ul>
<p>Note that while the Gregory-Hansen test does estimate break dates, it does not provide the statistical evidence to conclude whether these are statistically significant break dates or not. </p>
<h2 id="conclusion">Conclusion</h2>
<p>Today's blog looks closer at the Engle-Granger and Gregory-Hansen residual-based cointegration tests. By building a better understanding of how the tests work and what assumptions we make when running the tests, you will be better equipped to interpret the test results. </p>
<p>In particular, today we learned</p>
<ul>
<li>How to prepare for cointegration testing.</li>
<li>How to set up the specifications for cointegration tests. </li>
<li>How to interpret the results from the Engle-Granger and Gregory-Hansen cointegration tests. </li>
</ul>
<p>
    <!-- MathJax configuration -->
    <style>
        .mjx-svg-href {
            fill: "inherit" !important;
            stroke: "inherit" !important;
        }
    </style>
    <script type="text/x-mathjax-config">
        MathJax.Hub.Config({ TeX: { equationNumbers: {autoNumber: "AMS"} } });
    </script>
    <script type="text/javascript">
window.MathJax = {
  tex2jax: {
    inlineMath: [ ['$','$'] ],
    displayMath: [ ['$$','$$'] ],
    processEscapes: true,
    processEnvironments: true
  },
  // Center justify equations in code and markdown cells. Elsewhere
  // we use CSS to left justify single line equations in code cells.
  displayAlign: 'center',
  "HTML-CSS": {
    styles: {'.MathJax_Display': {"margin": 0}},
    linebreaks: { automatic: false }
  },
  "SVG": {
    styles: {'.MathJax_SVG_Display': {"margin": 0}},
    linebreaks: { automatic: false }
  },
  showProcessingMessages: false,
  messageStyle: "none",
  menuSettings: { zoom: "Click" },
  AuthorInit: function() {
    MathJax.Hub.Register.StartupHook("End", function() {
            var timeout = false, // holder for timeout id
            delay = 250; // delay after event is "complete" to run callback
            var shrinkMath = function() {
              //var dispFormulas = document.getElementsByClassName("formula");
              var dispFormulas = document.getElementsByClassName("MathJax_SVG_Display");
              if (dispFormulas){
                // caculate relative size of indentation
                var contentTest = document.getElementsByTagName("body")[0];
                var nodesWidth = contentTest.offsetWidth;
                // if you have indentation
                var mathIndent = MathJax.Hub.config.displayIndent; //assuming px's
                var mathIndentValue = mathIndent.substring(0,mathIndent.length - 2);
                for (var i=0; i<dispFormulas.length; i++){
                  var dispFormula = dispFormulas[i];
                  var wrapper = dispFormula;
                  //var wrapper = dispFormula.getElementsByClassName("MathJax_Preview")[0].nextSibling;
                  var child = wrapper.firstChild;
                  wrapper.style.transformOrigin = "center"; //or top-left if you left-align your equations
                  var oldScale = child.style.transform;
                  //var newValue = Math.min(0.80*dispFormula.offsetWidth / child.offsetWidth,1.0).toFixed(2);
                  var newValue = Math.min(dispFormula.offsetWidth / child.offsetWidth,1.0).toFixed(2);
                  var newScale = "scale(" + newValue + ")";
                  if(newValue != "NaN" && !(newScale === oldScale)){
                    wrapper.style.transform = newScale;
                    wrapper.style["margin-left"]= Math.pow(newValue,4)*mathIndentValue + "px";
                    var wrapperStyle = window.getComputedStyle(wrapper);
                    var wrapperHeight = parseFloat(wrapperStyle.height);
                    wrapper.style.height = "" + (wrapperHeight * newValue) + "px";
                    if(newValue === "1.00"){
                      wrapper.style.cursor = "";
                      wrapper.style.height = "";
                    }
                    else {
                      wrapper.style.cursor = "zoom-in";
                    }
                  }

                }
            }
            };
            shrinkMath();
            window.addEventListener('resize', function() {
              clearTimeout(timeout);
              timeout = setTimeout(shrinkMath, delay);
            });
          });
  }
}
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/MathJax.js?config=TeX-AMS_SVG"></script></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.aptech.com/blog/how-to-interpret-cointegration-test-results/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>A Guide to Conducting Cointegration Tests</title>
		<link>https://www.aptech.com/blog/a-guide-to-conducting-cointegration-tests/</link>
					<comments>https://www.aptech.com/blog/a-guide-to-conducting-cointegration-tests/#comments</comments>
		
		<dc:creator><![CDATA[Eric]]></dc:creator>
		<pubDate>Tue, 28 Jan 2020 14:26:32 +0000</pubDate>
				<category><![CDATA[Econometrics]]></category>
		<category><![CDATA[Time Series]]></category>
		<category><![CDATA[cointegration]]></category>
		<category><![CDATA[error correction model]]></category>
		<category><![CDATA[time series]]></category>
		<guid isPermaLink="false">https://www.aptech.com/?p=21405</guid>

					<description><![CDATA[Cointegration is an important tool for modeling the long-run relationships in time series data. If you work with time series data, you will likely find yourself needing to use cointegration at some point. This blog provides an in-depth introduction to cointegration and will cover all the nuts and bolts you need to get started. 
]]></description>
										<content:encoded><![CDATA[<h3 id="introduction">Introduction</h3>
<p>Cointegration is an important tool for modeling the long-run relationships in time series data. If you work with time series data, you will likely find yourself needing to use cointegration at some point.</p>
<p>This blog provides an in-depth introduction to cointegration and will cover all the nuts and bolts you need to get started. In particular, we will look at:</p>
<ul>
<li>The fundamentals of cointegration.</li>
<li>The error correction model.</li>
<li>How to prepare for cointegration testing. </li>
<li>What cointegration tests to use with and without structural breaks. </li>
<li>How to interpret cointegration tests. </li>
<li>How to perform cointegration tests in GAUSS.</li>
</ul>
<p>Though not necessary, you may find it helpful to review the blogs on <a href="https://www.aptech.com/blog/introduction-to-the-fundamentals-of-time-series-data-and-analysis/">time series modeling</a> and <a href="https://www.aptech.com/blog/how-to-conduct-unit-root-tests-in-gauss/">unit root testing</a> before continuing with this blog. </p>
<h2 id="what-is-cointegration">What is Cointegration?</h2>
<p>Economic theory suggests that many time series datasets will move together, fluctuating around a long-run equilibrium. In econometrics and statistics, this long-run equilibrium is tested and measured using the concept of cointegration.</p>
<p>Cointegration occurs when two or more nonstationary time series:</p>
<ul>
<li>Have a long-run equilibrium.</li>
<li>Move together in such a way that their linear combination results in a stationary time series.  </li>
<li>Share an underlying common stochastic trend. </li>
</ul>
<table>
 <thead>
 <tr>
      <th colspan="3">
         <h3 id="what-is-an-example-of-cointegrated-time-series"><br>What is an Example of Cointegrated Time Series? </h3>
      </th>
   </tr>

<tr><th>Field</th><th>Supporting Theory</th><th>Time Series</th></tr>
</thead>
<tbody>
<tr><td>Economics</td><td>The <a href="https://www.nber.org/chapters/c4405.pdf">permanent income hypothesis</a> describes how agents spread their consumption out  over their lifetime based on their expected income. </td><td>
Consumption and income.
</td></tr>
<tr><td>Economics</td><td>Purchasing power parity is a theory that relates the prices of a basket of goods across different countries.</td><td>Nominal exchange rates and domestic and foreign prices.</td></tr>
<tr><td>Finance</td><td>The present value model of stock prices implies a long-run relationship between stock prices and their dividends or earnings. 
</td><td>Stock prices and stock dividends/earnings.</td></tr>
<tr><td>Epidemiology</td><td><a href="https://ideas.repec.org/a/eee/insuma/v90y2020icp80-93.html">Joint mortality models</a> imply a long-run relationship between mortality rates across different demographics. </td><td>Male and female mortality rates.</td></tr>
<tr><td>Medicine</td><td><a href="https://papers.ssrn.com/sol3/papers.cfm?abstract_id=3311794">Time series methodologies</a> have been used to examine comorbidities of different types of cancers and trends in medical welfare.</td><td>Occurrence rates of different types of cancer.</td></tr>
</tbody>
</table>
<h3 id="the-mathematics-of-cointegration">The Mathematics of Cointegration</h3>
<p>To understand the mathematics of cointegration, let's consider a group of time series, $Y_t$, which is composed of three separate time series:</p>
<p>$$y_1 = (y_{11}, y_{12}, \ldots, y_{1t})$$
$$y_2 = (y_{21}, y_{22}, \ldots, y_{2t})$$
$$y_3 = (y_{31}, y_{32}, ..., y_{3t})$$ </p>
<p>All three series are <a href="https://www.aptech.com/blog/how-to-conduct-unit-root-tests-in-gauss/">nonstationary time series</a>. </p>
<p>Cointegration implies that while $y_1$, $y_2$, and $y_3$ are independently nonstationary, they can be combined in a way that their linear combination is stationary :</p>
<p>$$\beta Y_t = \beta_1 y_{1t} + \beta_2 y_{2t} + \beta_3 y_{3t} \sim I(0)$$</p>
<p><b>The Cointegrating Vector</b><br />
In the context of cointegration, $\beta$ is commonly known as the cointegrating vector. This vector:</p>
<ul>
<li>Dictates how cointegrating series are combined. </li>
<li>Does not have to be unique - there can be multiple ways of cointegrating.</li>
</ul>
<p><b>Normalization</b>
Because there can be multiple cointegrating vectors that fit the same economic model, we must impose identification restrictions to normalize the cointegrating vector for estimation. </p>
<p>A common normalization of the cointegrating vector is to set $\beta = ( 1,  -\beta_2, \ldots, -\beta_N)$. For example, applying these restrictions to our earlier system yields</p>
<p>$$\beta Y_t = y_{1t} - \beta_2 y_{2t} - \beta_3 y_{3t} \sim I(0)$$</p>
<p>Part of the appeal of this normalization is that it can be rewritten in a standard regression form</p>
<p>$$y_{1t} = \beta_2 y_{2t} + \beta_3 y_{3t} + u_t$$</p>
<p>where $u_t$ is a stationary cointegrating error component. Intuitively, $u_t$ can be thought of as short-term deviations from the long-run equilibrium. </p>
<p>While the regression format is a common normalization, it is important to remember that economic theory should inform our identifying restrictions. </p>
<h2 id="what-is-the-error-correction-model">What is the Error Correction Model?</h2>
<p>Cointegration implies that time series will be connecting through an error correction model. The error correction model is important in time series analysis because it allows us to better understand long-run dynamics. Additionally, failing to properly model cointegrated variables can result in biased estimates. </p>
<p>The error correction model:</p>
<ul>
<li>Reflects the long-run equilibrium relationships of variables. </li>
<li>Includes a short-run dynamic adjustment mechanism that describes how variables adjust when they are out of equilibrium.</li>
<li>Uses adjustment coefficients to measure the forces that push the relationship towards long-run equilibrium.</li>
</ul>
<h3 id="the-mathematics-of-the-error-correction-model">The Mathematics of the Error Correction Model</h3>
<p>Let's assume that there is a bivariate cointegrated system with $Y_t = (y_{1t}, y_{2t})$ and a cointegrating vector $\beta = (1, -\beta_2)$ such that </p>
<p>$$\beta Y_{t} = y_{1t} - \beta_2 y_{2t}$$</p>
<p>The error correction model depicts the dynamics of a variable as a function of the deviations from long-run equilibrium</p>
<p>$$\Delta y_{1t} = c_1 + \alpha_1 (y_{1,t-1} - \beta_2 y_{2,t-1}) + \sum_j \psi^j_{11} \Delta y_{1, t-j} + \sum_j \psi^j_{12} \Delta y_{2, t-j} + \epsilon_1t$$
$$\Delta y_{2t} = c_2 + \alpha_2 (y_{1,t-1} - \beta_2 y_{2,t-1}) + \sum_j \psi^j_{21} \Delta y_{1, t-j} + \sum_j \psi^j_{22} \Delta y_{2, t-j} + \epsilon_2t$$</p>
<table>
<thead>
<tr><th>Term</th><th>Description</th><th>Intuition</th></tr>
</thead>
<tbody>
<tr><td>$y_{1,t-1} - \beta_2 y_{2,t-1}$</td><td>Cointegrated long-run equilibrium</td><td>Because this is an equilibrium relationship, it plays a role in dynamic paths of both $y_{1t}$ and $y_{2t}$.</td></tr>
<tr><td>$\alpha_1$, $\alpha_2$</td><td>Adjustment coefficients</td><td>Captures the reactions of $y_{1t}$ and $y_{2t}$ to disequilibrium.</td></tr>
<tr><td>$\sum_j \psi^j_{11} \Delta y_{1, t-j} + \sum_j \psi^j_{12} \Delta y_{2, t-j}$</td><td>Autoregressive distributed lags</td><td>Captures additional dynamics.</td></tr>
</tbody>
</table>
<h3 id="estimating-the-error-correction-model">Estimating the Error Correction Model</h3>
<p>If the cointegrating vector has been previously estimated, then standard OLS or DOLS can be used to estimate the error correction relationship. In this case:</p>
<ul>
<li>The estimate of the cointegrating vector can be treated like a known variable.   </li>
<li>The estimated disequilibrium error can be treated like a known variable. </li>
</ul>
<p>The <a href="https://www.aptech.com/examples/tsmt/ecmfit-simulated/">ECM relationship can be estimated</a> using OLS, seemingly unrelated regressions (SUR), or maximum likelihood estimation.</p>
<h3 id="the-vector-error-correction-model-vecm">The Vector Error Correction Model (VECM)</h3>
<p>The vector error correction model (VECM) is the multivariate extension of the ECM. If we are working in a vector autoregressive context, cointegration implies a VECM such that</p>
<p>$$\Delta Y_t = \Phi D_t + \Pi Y_{t-1} + \Gamma_1 \Delta Y_{t-1} + \cdots + \Gamma_{p-1} \Delta Y_{t-p+1} + \epsilon_t$$ </p>
<p>Like the ECM, the VECM parameters reflect the long-run and short-run dynamics of system as shown in the table below:</p>
<table>
<thead>
<tr><th>Term</th><th>Description</th><th>Intuition</th></tr>
</thead>
<tbody>
<tr><td>$\Pi$</td><td>Long-run impact matrix.</td><td>$\Pi = \Pi_1 + \Pi_2 + \cdots + \Pi_p - I_n$, captures adjustments towards the long-run equilibrium and contains the cointegrating relationships.</td></tr>
<tr><td>$\Gamma_k$</td><td>Short-run impact matrix.</td><td>The short-run impact matrix is constructed from  $-\sum_{j=k+1}^p \Pi_j$ and captures short-run deviations from the equilibrium.</td></tr>
<tr><td>$D_t$</td><td>Deterministic terms.</td><td>These terms take the form $D_t = u_0 + u_1 t$ where $u_0$ is the constant component and $u_1 t$ is the trend component.</td></tr>
</tbody>
</table>
<h3 id="estimating-the-vecm">Estimating the VECM</h3>
<p>The VECM model can be estimated using the Johansen method:</p>
<ul>
<li>Estimate the appropriate VAR(p) model for $Y_t$.</li>
<li>Determine the number of cointegrating vectors, using a likelihood ratio test for the rank of $\Pi$.  </li>
<li>Impose identifying restrictions to normalize the cointegrating vector.</li>
<li>Using the normalized cointegrating vectors, estimate the resulting VECM by maximum likelihood.</li>
</ul>
<h2 id="preparing-for-cointegration-tests">Preparing For Cointegration Tests</h2>
<p>Before jumping directly to cointegration testing, there are a number of other time series modeling steps that we should consider first. </p>
<h3 id="establishing-underlying-theory">Establishing Underlying Theory</h3>
<p>One of the key considerations prior to testing for cointegration, is whether there is theoretical support for the cointegrating relationship.  It is important to remember that cointegration occurs when separate time series share an underlying stochastic trend. The idea of a shared trend should be supported by economic theory.</p>
<p>As an example, consider growth theory which suggests that productivity is a key driver of economic growth. As such, it acts as the common trend, driving the comovements of many indicators of economic growth. Hence, this theory implies that consumption, investment, and income are all cointegrated. </p>
<h3 id="time-series-visualization">Time Series Visualization</h3>
<p>One of the first steps in time series modeling should be data visualization. <a href="https://www.aptech.com/resources/tutorials/time-series-plots/">Time series plots</a> provide good preliminary insights into the behavior of time series data:</p>
<ul>
<li>Is a series mean-reverting or has explosive behavior?</li>
<li>Does it have a time trend?</li>
<li>Is there seasonality?</li>
<li>Are there structural breaks?</li>
</ul>
<h3 id="unit-root-testing">Unit Root Testing</h3>
<p>We've established that cointegration occurs between nonstationary, I(1), time series. This implies that before testing for or estimating a cointegrating relationship, we should perform <a href="https://www.aptech.com/why-gauss-for-unit-root-testing/">unit root testing</a>.  </p>
<p>Our previous blog, <a href="https://www.aptech.com/blog/how-to-conduct-unit-root-tests-in-gauss/">&quot;How to Conduct Unit Root Testing in GAUSS&quot;</a>, provides an in-depth look at how to perform unit root testing in GAUSS.  </p>
<p>GAUSS tools for performing unit root tests are available in a number of libraries, including the <a href="https://store.aptech.com/gauss-applications-category/time-series-mt.html">Time Series MT (TSMT)</a>, the open-source <a href="https://github.com/aptech/tspdlib">TSPDLIB</a>, and the <a href="https://store.aptech.com/third-party-applications-category/coint-2-1-co-integrated-systems.html">coint</a> libraries.  All of these can be directly located and installed using the <a href="https://www.aptech.com/blog/gauss-package-manager-basics/">GAUSS package manager</a>. </p>
<p>Full example programs for testing for unit roots using TSMT procedures and TSPDLIB procedures are available on our <a href="https://github.com/aptech/gauss_blog/tree/master/time_series/cointegration-1.20.19">Aptech GitHub page</a>. </p>
<table>
<thead>
<tr><th>Panel Data Unit Root Test</th><th>TSMT procedure</th><th>TSPDLIB procedure</th></tr>
</thead>
<tbody>
<tr><td><b>Hadri</b></td><td>hadri</td><td></td></tr>
<tr><td><b>Im, Pesaran, and Shin</b></td><td>ips</td><td></td></tr>
<tr><td><b>Levin-Lu-Chin</b></td><td>llc</td><td></td></tr>
<tr><td><b>Schmidt and Perron LM test</b></td><td></td><td>lm</td></tr>
<tr><td><b>Breitung and Das</b></td><td>breitung</td><td></td></tr>
<tr><td><b>Cross-sectionally augmented IPS test (CIPS)</b></td><td></td><td><a href="https://github.com/aptech/tspdlib/blob/master/examples/cips.e">cips</a></td></tr>
<tr><td><b>Panel analysis of nonstationary and idiosyncratic and common (PANIC)</b></td><td></td><td><a href="https://github.com/aptech/tspdlib/blob/master/examples/panic_bng.e">bng_panic</a></td></tr>
</tbody>
</table>
<table>
<thead>
<tr><th>Time Series Unit Root Test</th><th>TSMT procedure</th><th>TSPDLIB procedure</th></tr>
</thead>
<tbody>
<tr><td><b>Augmented-Dickey Fuller</b></td><td>vmadfmt</td><td><a href="https://github.com/aptech/tspdlib/blob/master/examples/adf.e">adf</a></td></tr>
<tr><td><b>Phillips-Perron</b></td><td>vmppmt</td><td><a href="https://github.com/aptech/tspdlib/blob/master/examples/pp.e">pp</a></td></tr>
<tr><td><b>KPSS</b></td><td>kpss</td><td>lmkpss</td></tr>
<tr><td><b>Schmidt and Perron LM test</b></td><td></td><td>lm</td></tr>
<tr><td><b>GLS-ADF</b></td><td>dfgls</td><td><a href="https://github.com/aptech/tspdlib/blob/master/examples/dfgls.e">dfgls</a></td></tr>
<tr><td><b>Quantile ADF</b></td><td></td><td><a href="https://github.com/aptech/tspdlib/blob/master/examples/qr_adf.e">qr_adf</a></td></tr>
</tbody>
</table>
<h3 id="testing-for-structural-breaks">Testing for structural breaks</h3>
<p>A complete time series analysis should consider the possibility that <a href="https://www.aptech.com/structural-breaks/">structural breaks</a> have occurred. In the case that structural breaks have occurred, standard tests for cointegration are invalid. </p>
<p>Therefore, it is important to:</p>
<ul>
<li>Test whether structural breaks occur in the individual series. </li>
<li>In the case that there is evidence of structural breaks, employ cointegration tests that allow for structural breaks.</li>
</ul>
<p>The GAUSS <code>sbreak</code> procedure, available in TSMT, is an easy-to-use tool for identifying multiple, unknown structural breaks. </p>
<h2 id="cointegration-tests">Cointegration Tests</h2>
<p>In order to test for cointegration, we must test that a long-run equilibrium exists for a group of data. There are a number of things that need to be considered:</p>
<ul>
<li>Are there multiple cointegrating vectors or just one?</li>
<li>Is the cointegrating vector known or does it need to be estimated?</li>
<li>What deterministic components are included in the cointegrating relationship?</li>
<li>Do we suspect structural breaks in the cointegrating relationship?</li>
</ul>
<p>In this section, we will show how to use these questions to guide cointegration testing without structural breaks.  </p>
<h3 id="the-engle-granger-cointegration-test">The Engle-Granger Cointegration Test</h3>
<p>The Engle-Granger cointegration test considers the case that there is a single cointegrating vector. The test follows the very simple intuition that if variables are cointegrated, then the residual of the cointegrating regression should be stationary. </p>
<p><b> Forming the cointegrating residual</b><br />
How to form the cointegrating residual depends on if the cointegrating vector is known or must be estimated:</p>
<p><b>If the cointegrating vector is known,</b> the cointegrating residuals are directly computed using $u_t = \beta Y_t$. The residuals should be stationary and:</b>  </p>
<ul>
<li>Any standard unit root tests, such as the ADF or PP test, can be used to test the residuals. The test statistics follow the standard distributions.</li>
<li>The test compares the null hypothesis of no cointegration against the alternative of cointegration.</li>
<li>The cointegrating residuals should be examined for the presence of a constant or trend, and the appropriate unit root test should be utilized. </li>
</ul>
<p><b>If the cointegrating vector is unknown</b>, OLS is used to estimate the normalized cointegrating vector from the regression
$$y_{1t} = c + \beta y_{2t} + u_{t}$$</p>
<ul>
<li>The residuals from the cointegrating regression are estimated
$$\hat{u_t} = y_{1t} - \hat{c} - \hat{\beta_2}y_{2t}$$</li>
<li>Any standard <a href="https://www.aptech.com/blog/how-to-conduct-unit-root-tests-in-gauss/">unit root test</a>, such as the ADF or PP test, can be used to test the residuals. The test statistics follow the nonstandard Phillips-Ouliaris (PO) distributions. </li>
<li>The PO distribution depends on the trend behavior of the data. </li>
</ul>
<h3 id="the-johansen-tests">The Johansen Tests</h3>
<p>There are two Johansen cointegrating tests for the VECM context, the trace test and the maximal eigenvalue test. These tests hinge on the intuition that in the VECM, the rank of the long-run impact matrix, $\Pi$, determines if the VAR(p) variables are cointegrated. </p>
<p>Since the rank of the long-run impact matrix equals the number of cointegrating relationships:</p>
<ul>
<li>A likelihood ratio statistic for determining the rank of $\Pi$ can be used to establish the number of cointegrating relationships.</li>
<li>Sequential testing can be used to test the number, $k$, of the cointegrating relationships. </li>
</ul>
<p>The Johansen testing process has two general steps:</p>
<ol>
<li>Estimate the VECM model using maximum likelihood under various assumptions:
<ul>
<li>With and without trend. </li>
<li>With and without constant. </li>
<li>With varying number, $k$, of cointegrating vectors.</li>
</ul></li>
<li>Compare the models using likelihood ratio tests. </li>
</ol>
<p><b>The Johansen Trace Statistics</b><br />
The Johansen trace statistic:</p>
<ul>
<li>Is a likelihood ratio test of an unrestricted VECM against the restricted VECM with $k$ cointegrating vectors, where $k = m-1, \ldots, 0$.   </li>
<li>Is formed from the trace of a diagonal matrix of generalized eigenvalues from $\Pi$. </li>
<li>As the $LR_{trace}(k)$ statistic gets closer to zero, we are less likely to reject the null hypothesis. </li>
<li>If the $LR_{trace}(k)>CV$, then the null hypothesis is rejected. </li>
</ul>
<p>The Johansen testing procedure sequentially tests the null hypothesis that the number of cointegrating vectors, $k = m$ against the alternative that $k > m$.</p>
<table>
<thead>
<tr><th>Stage</th><th>Null Hypothesis</th><th>Alternative</th><th>Conclusion</th></tr>
</thead>
<tbody>
<tr><td>One</td><td>$H_0: k = 0$</td><td>$H_A: k&gt;0$</td><td>If $H_0$ cannot be rejected, stop testing, and $k = 0$. If null is rejected, perform next test.</td></tr>
<tr><td>Two</td><td>$H_0: k \leq 1$</td><td>$H_A: k&gt;1$</td><td>If $H_0$ cannot be rejected, stop testing, and $k \leq 1$. If null is rejected, perform next test.</td></tr>
<tr><td>Three</td><td>$H_0: k \leq 2$</td><td>$H_A: k&gt;2$</td><td>If $H_0$ cannot be rejected, stop testing, and $k \leq 2$. If null is rejected, perform next test.</td></tr>
<tr><td>m-1</td><td>$H_0: k \leq m-1$</td><td>$H_A: k&gt;m-1$</td><td>If $H_0$ cannot be rejected, stop testing, and $k \leq m-1$. If null is rejected, perform next test.</td></tr>
</tbody>
</table>
<p>The test statistic follows a nonstandard distribution and depends on the dimension and the specified deterministic trend.</p>
<p><b>The Johansen Maximum Eigenvalue Statistic</b><br />
The maximal eigenvalue statistic:</p>
<ul>
<li>Considers the null hypothesis that the cointegrating rank is $k$ against the alternative hypothesis that the cointegrating rank is $k + 1$.</li>
<li>The statistic follows a nonstandard distribution.</li>
</ul>
<h2 id="cointegration-test-with-structural-breaks">Cointegration Test with Structural Breaks</h2>
<p>In the case that there are structural breaks in the cointegrating relationship, the cointegration tests in the previous station should not be used. In this section we look at three tests for cointegration with structural breaks:</p>
<ul>
<li>The <a href="https://www.sciencedirect.com/science/article/abs/pii/0304407669416857">Gregory and Hansen (1996)</a> test for cointegration with a single structural break.</li>
<li>The <a href="https://ideas.repec.org/c/boc/bocode/g00006.html">Hatemi-J test (2009)</a> for cointegration with two structural breaks. </li>
<li>The Maki test for cointegration with multiple structural breaks. </li>
</ul>
<h3 id="the-gregory-and-hansen-cointegration-test">The Gregory and Hansen Cointegration Test</h3>
<p>The Gregory and Hansen (1996) cointegration test is a residual-based cointegration test that tests the null hypothesis of no cointegration against the alternative of cointegration in the presence of a <a href="https://www.aptech.com/structural-breaks/">single regime shift</a>. </p>
<p>The <a href="https://www.sciencedirect.com/science/article/abs/pii/0304407669416857">Gregory and Hansen (1996)</a> test:</p>
<ul>
<li>Is an extension of the ADF and PP residual tests for cointegration.</li>
<li>Allows for unknown regimes shifts in either the intercept or the coefficient vector.</li>
<li>Is valid for three different model cases: level shift with trend, regime shifts (changes in coefficients), regime shift with a shift in trend.</li>
</ul>
<p>Because the structural break date is unknown, the test computes the cointegration test statistic for each possible breakpoint, and the smallest test statistics are used.</p>
<p>Gregory and Hansen (1996) suggest running their tests in combination with the standard cointegration tests:</p>
<ul>
<li>If the standard ADF test and the Gregory and Hansen ADF test both reject the null hypothesis of no cointegration, there is evidence in support of cointegration. </li>
<li>If the standard ADF test does not reject the null hypothesis but the Gregory and Hansen ADF does, structural change in the cointegrating vector <em>may</em> be important.</li>
<li>If the standard ADF test and the Gregory and Hansen ADF both reject the null hypothesis, there is no evidence from this test that structural change has occurred. </li>
</ul>
<h3 id="the-hatemi-j-cointegration-test-with-two-structural-breaks">The Hatemi-J Cointegration Test with Two Structural Breaks</h3>
<p>The Hatemi-J cointegration test is an extension of the Gregory and Hansen cointegration test. It allows for two possible structural breaks with unknown timing.  </p>
<h3 id="the-maki-cointegration-test">The Maki Cointegration Test</h3>
<p>The Maki cointegration test builds on the Gregory and Hansen and the Hatemi-J cointegration tests to allow for an unknown number of structural breaks. </p>
<h2 id="where-to-find-cointegration-tests-for-gauss">Where to Find Cointegration Tests for GAUSS</h2>
<p>GAUSS tools for performing cointegration tests and estimating VECM models are available in a number of libraries, including the <a href="https://store.aptech.com/gauss-applications-category/time-series-mt.html">Time Series MT (TSMT) library</a>,  <a href="https://github.com/aptech/tspdlib">TSPDLIB</a>, and the <a href="https://store.aptech.com/third-party-applications-category/coint-2-1-co-integrated-systems.html">coint</a> libraries.  All of these can be directly located and installed using the <a href="https://www.aptech.com/blog/gauss-package-manager-basics/">GAUSS package manager</a>. </p>
<table>
<thead>
<tr><th>Cointegration test</th><th>Null Hypothesis</th><th>Decision Rule</th><th>GAUSS library</th></tr>
</thead>
<tbody>
<tr><td><b>Engle-Granger (ADF)</b></td><td>No cointegration.</td><td>Reject the null hypothesis if the $ADF$ test statistic is less than the critical value.</td><td>TSMT, tspdlib, coint</td></tr>
<tr><td><b>Phillips</b></td><td>No cointegration.</td><td>Reject the null hypothesis if the $Z$ test statistic is less than the critical value.</td><td>coint, tspdlib</td></tr>
<tr><td><b>Stock and Watson common trend</b></td><td>$Y$ is a non-cointegrated system after allowing for the pth order polynomial common trend.</td><td>Reject the null hypothesis if the $SW$ test statistic is less than the critical value.</td><td>coint</td></tr>
<tr><td><b>Phillips and Ouliaris </b></td><td>$Y$ and $X$ are not cointegrated.</td><td>Reject the null hypothesis if the $P_u$ or $P_z$ statistic is greater than the critical value.</td><td>coint, tspdlib</td></tr>
<tr><td><b>Johansen trace</b></td><td>Rank of $\Pi$ is equal to $r$ against the alternative that the rank of $\Pi$ is greater than $r$.</td><td>Reject the null hypothesis if $LM_{max}(k)$ is greater than the critical value.</td><td>TSMT, coint</td></tr>
<tr><td><b>Johansen maximum eigenvalue</b></td><td>Rank of $\Pi$ is equal to $r$ against the alternative that the rank of $\Pi$ is equal to $r+1$.</td><td>Reject the null hypothesis if $LM(r)$ is greater than the critical value.</td><td>TSMT, coint</td></tr>
<tr><td><b>Gregory and Hansen</b></td><td>No cointegration against the alternative of cointegration with one structural break.</td><td>Reject the null hypothesis if $ADF$, $Z_{\alpha}$, or $Z_t$ are less than the critical value.</td><td>tspdlib</td></tr>
<tr><td><b>Hatemi-J</b></td><td>No cointegration against the alternative of cointegration with an two structural breaks.</td><td>Reject the null hypothesis if $ADF$, $Z_{\alpha}$, or $Z_t$ are less than the critical values.</td><td>tspdlib</td></tr>
<tr><td><b>Maki</b></td><td>No cointegration against the alternative of cointegration with an unknown number of breaks.</td><td>Reject the null hypothesis if $ADF$, $Z_{\alpha}$, or $Z_t$ are less than the critical value.</td><td>tspdlib</td></tr>
<tr><td><b>Shin test</b></td><td>Cointegration.</td><td>Reject the null hypothesis if the test statistic is less than the critical value.</td><td>tspdlib</td></tr>
</tbody>
</table>
<h2 id="how-to-test-for-cointegration-using-gauss">How to Test for Cointegration using GAUSS</h2>
<p>In this section, we will test for cointegration between monthly gold and silver prices, using historic monthly price date starting in 1915. Specifically, we will work through several stages of analysis:</p>
<ol>
<li>Graphing the data and checking deterministic behavior. </li>
<li>Testing each series for unit roots. </li>
<li>Testing for cointegration without structural breaks. </li>
<li>Testing for cointegration with structural breaks. </li>
</ol>
<h3 id="graphing-the-data">Graphing the Data</h3>
<p>As a first step, we will create a <a href="https://www.aptech.com/resources/tutorials/tsmt/wpi-visualizing-time-series-data/">time series graph</a> of our data. This allows us to visually examine the deterministic trends in our data.</p>
<p><a href="https://www.aptech.com/wp-content/uploads/2020/01/gold_silver_prices_small.jpg"><img src="https://www.aptech.com/wp-content/uploads/2020/01/gold_silver_prices_small.jpg" alt="Shows comovements between gold and silver prices since 1915." width="800" height="600" class="aligncenter size-full wp-image-21494" /></a></p>
<p>From our graphs, we can draw some preliminary conclusions about the dynamics of gold and silver prices over our time period:</p>
<ul>
<li>There appears to be some foundation for the comovement of silver and gold prices.   </li>
<li>Neither gold nor silver prices appear to have a time trend. </li>
</ul>
<h3 id="testing-each-series-for-unit-roots">Testing Each Series for Unit Roots</h3>
<p>Before testing if silver and gold prices are cointegrated, we should test if the series have unit roots. We can do this using the unit roots tests available in the TSMT and TSPDLIB libraries.  </p>
<table>
<thead>
 <tr>
      <th colspan="3">
         Gold monthly closing prices (2015-2020)
      </th>
   </tr>
<tr><th>Time Series Unit Root Test</th><th>Test Statistic</th><th>Conclusion</th></tr>
</thead>
<tbody>
<tr><td><b>Augmented-Dickey Fuller</b></td><td>-1.151</td><td>Cannot reject the null hypothesis of unit root.</td></tr>
<tr><td><b>Phillips-Perron</b></td><td>-1.312</td><td>Cannot reject the null hypothesis of unit root.</td></tr>
<tr><td><b>KPSS</b></td><td>2.102</td><td>Reject the null hypothesis of stationarity at the 1% level.</td></tr>
<tr><td><b>Schmidt and Perron LM test</b></td><td>-2.399</td><td>Cannot reject the null hypothesis of unit root.</td></tr>
<tr><td><b>GLS-ADF</b></td><td>-0.980</td><td>Cannot reject the null hypothesis of unit root.</td></tr>
</tbody>
</table>
<table>
<thead>
 <tr>
      <th colspan="3">
         Silver monthly closing prices (2015-2020)
      </th>
   </tr>
<tr><th>Time Series Unit Root Test</th><th>Test Statistic</th><th>Conclusion</th></tr>
</thead>
<tbody>
<tr><td><b>Augmented-Dickey Fuller</b></td><td>-5.121</td><td>Reject the null hypothesis of unit root at the 1% level.</td></tr>
<tr><td><b>Phillips-Perron</b></td><td>-5.446</td><td>Reject the null hypothesis of unit root at the 1% level.</td></tr>
<tr><td><b>KPSS</b></td><td>0.856</td><td>Reject the null hypothesis of stationarity at the 1% level.</td></tr>
<tr><td><b>Schmidt and Perron LM test</b></td><td>-4.729 </td><td>Reject the null hypothesis of unit root at the 1% level.</td></tr>
<tr><td><b>GLS-ADF</b></td><td>-4.895</td><td>Reject the null hypothesis of unit root at the 1% level.</td></tr>
</tbody>
</table>
<p>These results provide evidence that gold prices are nonstationary but suggest that the silver prices are stationary.
At this point, we would not likely proceed with cointegration testing or we may wish to perform additional unit root testing. For example, we may want to perform <a href="https://www.aptech.com/blog/unit-root-tests-with-structural-breaks/">unit root tests that allow for structural breaks</a>. </p>
<p>The GAUSS code for the tests in this section is available <a href="https://github.com/aptech/gauss_blog/blob/master/time_series/cointegration-1.20.19/examples/2_unitroot_tsmt.e">here</a>.</p>
<h3 id="testing-for-cointegration">Testing for Cointegration</h3>
<p>Now, let's test for cointegration without structural breaks using two different tests, the Johansen tests and the Engle-Granger test.</p>
<p><b> The Johansen Tests</b><br />
We will use the <code>vmsjmt</code> procedure from the TSMT library. This procedure should be used with the <code>vmc_sjamt</code> and <code>vmc_sjtmt</code> procedures, which find the critical values for the Maximum Eigenvalue and Trace statistics, respectively. </p>
<p>The <code>vmsjmt</code> procedure requires four inputs:</p>
<hr>
<dl>
<dt>y</dt>
<dd>Matrix, contains the data to be tested for cointegration.</dd>
<dt>p</dt>
<dd>Scalar, the order of the time polynomial in the fitted regression. Set to $p=-1$ for no deterministic component, $p=0$ for a constant only, $p=1$ for a constant and trend.</dd>
<dt>k</dt>
<dd>Scalar, the number of lagged differences to use when computing the estimator.</dd>
<dt>no_det</dt>
<dd>Scalar, set $no\_det = 1$ to suppress the constant term from the fitted regression and include it in the cointegrating regression.
<hr></dd>
</dl>
<p>The <code>vmsjmt</code> procedure returns both the Johansen Trace and the Johansen Maximum Eigenvalue statistic. In addition, it returns the associated eigenvalues and eigenvectors. </p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">new;

// Load tsmt library
library tsmt;

// Set filename (with path) for loading
fname2 = __FILE_DIR $+ "commodity_mon.dat";

// Load real prices data
y_test_real = loadd(fname2, "P_gold_real + P_silver_real");

// No deterministic component 
// the fitted regression
p = -1;

// Set number of lagged differences
// for computing estimator
k = 2;

// No determinant
no_det = 0;

{ ev, evec, trace_stat, max_ev }  = vmsjmt(y_test_real, p, k, no_det);
cv_lr2 = vmc_sjamt(cols(y), p);
cv_lr1 = vmc_sjtmt(cols(y), p);</code></pre>
<p>Both <code>trace_stat</code> and <code>max_ev</code> will contain statistics for all possible ranks of $\Pi$. </p>
<p>For example, since we are testing for cointegration of just two time series, there will be at most one cointegrating vector. This means <code>trace_stat</code> and <code>max_ev</code> will be 2 x 1 matrices, testing both null hypotheses that $r=0$ and $r=1$. </p>
<table>
<thead>
<tr><th>Test</th><th>Test Statistic</th><th>10% Critical Value</th><th>Conclusion</th></tr>
</thead>
<tbody>
<tr><td><b>Johansen Trace Statistic</b></td><td>$$H_0: r=1, 56.707$$ $$H_0: r=0, 0.0767$$</td><td>10.46</td><td>Cannot reject the null hypothesis that $r=0$.</td></tr>
<tr><td><b>Johansen Maximum Eigenvalue</b></td><td>$$H_0: r=1, 56.631$$ $$H_0: r=0, 0.0766$$</td><td>9.39</td><td>Cannot reject the null hypothesis that $r=0$.</td></tr>
</tbody>
</table>
<p>These results indicate that there is no cointegration between monthly gold and silver prices. This should not be a surprise, given the results of our unit root testing. </p>
<div class="alert alert-info" role="alert">In the table above we report the results for all possible number of cointegrating vectors ($k=0$ and $k=1$). This is consistent with the results that are returned from <code>vmsjmt</code>. However, the Johansen tests are sequential tests and since we cannot reject the null that $k=0$ for either test, we technically do not need to continue testing for any higher rank. </div>
<p><b> The Engle-Granger</b><br />
Since there is only one possible cointegrating vector for this system, we could have also used the Engle-Granger test for cointegration. This test can be implemented using the <code>coint_egranger</code> procedure from the TSPDLIB library. </p>
<p>The <code>coint_egranger</code> procedure requires five inputs:</p>
<hr>
<dl>
<dt>y</dt>
<dd>Vector, independent variable in the testing regression. This is the variable the cointegrating variable is normalized to.</dd>
<dt>X</dt>
<dd>Matrix, dependent variable(s) in the testing regression. This should contain all other variables.</dd>
<dt>model</dt>
<dd>Scalar, specifies which deterministic components to include in the model. Set equal to 0 to include no deterministic components, 1 to include a constant, and 2 to include a constant and trend.</dd>
<dt>pmax</dt>
<dd>Scalar, the maximum number of lags to include in the cointegrating vector.</dd>
<dt>ic</dt>
<dd>Scalar, which information criteria to use to select the lags included in the ADF regression. Set equal to 1 for the AIC, 2 for the SIC.
<hr></dd>
</dl>
<p>The <code>coint_egranger</code> procedure returns the test statistic along with the 1%, 5% and 10% critical values.</p>
<p>Using the data already loaded in the previous example:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss"> /*
** Information Criterion:
** 1=Akaike;
** 2=Schwarz;
** 3=t-stat sign.
*/
ic = 2;

// Maximum number of lags
pmax = 12;

// No constant or trend
model = 0
{ tau0, cvADF0 } = coint_egranger(y_test_real[., 1], y_test_real[., 2], model, pmax, ic);

// Constant
model = 1
{ tau1, cvADF1 } = coint_egranger(y_test_real[., 1], y_test_real[., 2], model, pmax, ic);

// Constant and trend
model = 2
{ tau2, cvADF2 } = coint_egranger(y_test_real[., 1], y_test_real[., 2], model, pmax, ic);</code></pre>
<table>
<thead>
<tr><th>Test</th><th>Test Statistic</th><th>10% Critical Value</th><th>Conclusion</th></tr>
</thead>
<tbody>
<tr><td><b>Engle-Granger, no constant</b></td><td>-3.094</td><td>-2.450</td><td>Reject the null of no cointegration at the 10% level.</td></tr>
<tr><td><b>Engle-Granger, constant</b></td><td>-1.609</td><td>-3.066 </td><td>Cannot reject the null hypothesis of no cointegration.</td></tr>
<tr><td><b>Engle-Granger, constant and trend</b></td><td>-2.327</td><td>-3.518</td><td>Cannot reject the null hypothesis of no cointegration.</td></tr>
</tbody>
</table>
<p>These results provide evidence for our conclusion that there is no cointegration between gold and silver prices. Note, however, that these results are not conclusive and depend on whether we include a constant. This sheds light on the importance of including the correct deterministic components in our model. </p>
<h3 id="testing-for-cointegration-with-structural-breaks">Testing for Cointegration with Structural Breaks</h3>
<p>To be thorough we should also test for cointegration using tests that allow for a structural break. As an example, let's use the Gregory-Hansen test to compare the null hypothesis of no cointegration against the alternative that there is cointegration with one structural break.</p>
<p>This test can be implemented using the <code>coint_ghansen</code> procedure from the TSPDLIB. </p>
<p>The <code>coint_ghansen</code> procedure requires eight inputs:</p>
<hr>
<dl>
<dt>y</dt>
<dd>Vector, dependent variable in the testing regression. This is the variable the cointegrating variable is normalized to.</dd>
<dt>X</dt>
<dd>Matrix, independent variable(s) in the testing regression. This should contain all other variables.</dd>
<dt>model</dt>
<dd>Scalar, specified what type of regime shifts to include. Set equal to 1 for a level shift (C model), 2 for level shift with trend (C/T model), 3 for regime shift (C/S model), and 4 for regime and trend shifts.</dd>
<dt>bwl</dt>
<dd>Scalar, Bandwidth for kernel estimator for Phillips-Perron type test.</dd>
<dt>pmax</dt>
<dd>Scalar, the maximum number of lags to include in the cointegrating vector.</dd>
<dt>ic</dt>
<dd>Scalar, which information criteria to use to select the lags included in the ADF regression. Set equal to 1 for the AIC, 2 for the SIC.</dd>
<dt>varm</dt>
<dd>Scalar, long-run consistent variance type to use for the Phillips-Perron type test:
                 1 = iid,
                 2 = Bartlett,
                 3 = Quadratic Spectral (QS),
                 4 = SPC with Bartlett /see (Sul, Phillips &amp; Choi, 2005),
                 5 = SPC with QS,
                 6 = Kurozumi with Bartlett,
                 7 = Kurozumi with QS.</dd>
<dt>trimm</dt>
<dd>Scalar, amount to trim from consideration as break date.
<hr></dd>
</dl>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">/*
** Information Criterion:
** 1=Akaike;
** 2=Schwarz;
** 3=t-stat sign.
*/
ic = 2;

//Maximum number of lags
pmax = 12;

// Trimming rate
trimm= 0.15;

// Long-run consistent variance estimation method
varm = 3;

// Bandwidth for kernel estimator
T = rows(y_test_real);
bwl = round(4 * (T/100)^(2/9));

// Level shift
model = 1;
{ ADF_min1, TBadf1, Zt_min1, TBzt1, Za_min1, TBza1, cvADFZt1, cvZa1 }=
    coint_ghansen(y_test_real[., 1], y_test_real[., 2], model, bwl, ic, pmax, varm, trimm);

// Level shift with trend
model = 2;
{ ADF_min2, TBadf2, Zt_min2, TBzt2, Za_min2, TBza2, cvADFZt2, cvZa2 }=
    coint_ghansen(y_test_real[., 1], y_test_real[., 2], model, bwl, ic, pmax, varm, trimm);

// Regime shift
model = 3;
{ ADF_min3, TBadf3, Zt_min3, TBzt3, Za_min3, TBza3, cvADFZt3, cvZa3 }=
    coint_ghansen(y_test_real[., 1], y_test_real[., 2], model, bwl, ic, pmax, varm, trimm);

// Regime shift with trend
model = 4;
{ ADF_min4, TBadf4, Zt_min4, TBzt4, Za_min4, TBza4, cvADFZt4, cvZa4 }=
    coint_ghansen(y_test_real[., 1], y_test_real[., 2], model, bwl, ic, pmax, varm, trimm);</code></pre>
<p>The <code>coint_ghansen</code> has eight returns:</p>
<hr>
<dl>
<dt>ADFmin</dt>
<dd>Scalar, the minimum $ADF$ test statistic across all breakpoints.</dd>
<dt>TBadf</dt>
<dd>Scalar, the breakpoint associated with the minimum $ADF$ statistic.</dd>
<dt>Ztmin</dt>
<dd>Scalar, the minimum $Z_t$ test statistic across all breakpoints.</dd>
<dt>TBzt</dt>
<dd>Scalar, the breakpoint associated with the minimum $Z_t$ statistic.</dd>
<dt>Zamin</dt>
<dd>Scalar, the minimum $Z_{\alpha}$ test statistic across all breakpoints.</dd>
<dt>TBza</dt>
<dd>Scalar, the breakpoint associated with the minimum $Z_{\alpha}$ statistic.</dd>
<dt>cvADFZt</dt>
<dd>Vector, the 1%, 5%, and 10% critical values for the $ADF$ and $Z_t$ statistics.</dd>
<dt>cvZa</dt>
<dd>Vector, the 1%, 5%, and 10% critical values for the $Z_{\alpha}$ statistic.
<hr></dd>
</dl>
<table>
<thead>
<tr><th>Test</th><th>$ADF$ Test Statistic</th><th>$Z_t$ Test Statistic</th><th>$Z_{\alpha}$ Test Statistic</th><th>10% Critical Value $ADF$,$Z_t$</th><th>10% Critical Value $Z_{\alpha}$</th><th>Conclusion</th></tr>
</thead>
<tbody>
<tr><td><b>Gregory-Hansen, Level shift</b></td><td>-3.887</td><td>-4.331</td><td>-39.902</td><td>-4.34</td><td>-36.19</td><td>Cannot reject the null of no cointegration for $ADF$ and $Z_t$. Reject the null of no cointegration at the 10% level for $Z_{\alpha}$.</td></tr>
<tr><td><b>Gregory-Hansen, Level shift with trend</b></td><td>-3.915</td><td>-5.010</td><td>-50.398</td><td>-4.72</td><td>-43.22</td><td>Reject the null of no cointegration at the 10% level for $Z_{\alpha}$ and $Z_t$. Cannot reject the null for $ADF$ test.</td></tr>
<tr><td><b>Gregory-Hansen, Regime change</b></td><td>-5.452</td><td>-6.4276</td><td>-80.379</td><td>-4.68</td><td>-41.85</td><td>Reject the null of no cointegration at the 10% level.</td></tr>
<tr><td><b>Gregory-Hansen, Regime change with trend</b></td><td>-6.145</td><td>-7.578</td><td>-106.549</td><td>-5.24</td><td>-53.31</td><td>Reject the null of no cointegration at the 10% level.</td></tr>
</tbody>
</table>
<p>Note that our test for cointegration with one structural break is inconsistent and depends on which type of structural breaks we include in our model. This provides some indication that further exploration of structural breaks is needed. </p>
<p>Some examples of additional steps that we could take:</p>
<ol>
<li>Perform more complete structural breaks testing to inform if structural breaks are valid, how many structural breaks should be included, and which structural break model is most appropriate. </li>
<li>Perform cointegration tests that are most consistent with the structural breaks analysis. </li>
</ol>
<h2 id="conclusion">Conclusion</h2>
<p>Congratulations! You now have an established guide for cointegration and the background you need to perform cointegration testing. </p>
<p>In particular, today's blog covered:</p>
<ul>
<li>The fundamentals of cointegration.</li>
<li>The error correction model.</li>
<li>How to prepare for cointegration testing. </li>
<li>What cointegration tests to use with and without structural breaks. </li>
<li>How to interpret cointegration tests. </li>
<li>How to perform cointegration tests in GAUSS.</li>
</ul>
<p>    <!-- MathJax configuration -->
    <style>
        .mjx-svg-href {
            fill: "inherit" !important;
            stroke: "inherit" !important;
        }
    </style>
    <script type="text/x-mathjax-config">
        MathJax.Hub.Config({ TeX: { equationNumbers: {autoNumber: "AMS"} } });
    </script>
    <script type="text/javascript">
window.MathJax = {
  tex2jax: {
    inlineMath: [ ['$','$'] ],
    displayMath: [ ['$$','$$'] ],
    processEscapes: true,
    processEnvironments: true
  },
  // Center justify equations in code and markdown cells. Elsewhere
  // we use CSS to left justify single line equations in code cells.
  displayAlign: 'center',
  "HTML-CSS": {
    styles: {'.MathJax_Display': {"margin": 0}},
    linebreaks: { automatic: false }
  },
  "SVG": {
    styles: {'.MathJax_SVG_Display': {"margin": 0}},
    linebreaks: { automatic: false }
  },
  showProcessingMessages: false,
  messageStyle: "none",
  menuSettings: { zoom: "Click" },
  AuthorInit: function() {
    MathJax.Hub.Register.StartupHook("End", function() {
            var timeout = false, // holder for timeout id
            delay = 250; // delay after event is "complete" to run callback
            var shrinkMath = function() {
              //var dispFormulas = document.getElementsByClassName("formula");
              var dispFormulas = document.getElementsByClassName("MathJax_SVG_Display");
              if (dispFormulas){
                // caculate relative size of indentation
                var contentTest = document.getElementsByTagName("body")[0];
                var nodesWidth = contentTest.offsetWidth;
                // if you have indentation
                var mathIndent = MathJax.Hub.config.displayIndent; //assuming px's
                var mathIndentValue = mathIndent.substring(0,mathIndent.length - 2);
                for (var i=0; i<dispFormulas.length; i++){
                  var dispFormula = dispFormulas[i];
                  var wrapper = dispFormula;
                  //var wrapper = dispFormula.getElementsByClassName("MathJax_Preview")[0].nextSibling;
                  var child = wrapper.firstChild;
                  wrapper.style.transformOrigin = "center"; //or top-left if you left-align your equations
                  var oldScale = child.style.transform;
                  //var newValue = Math.min(0.80*dispFormula.offsetWidth / child.offsetWidth,1.0).toFixed(2);
                  var newValue = Math.min(dispFormula.offsetWidth / child.offsetWidth,1.0).toFixed(2);
                  var newScale = "scale(" + newValue + ")";
                  if(newValue != "NaN" && !(newScale === oldScale)){
                    wrapper.style.transform = newScale;
                    wrapper.style["margin-left"]= Math.pow(newValue,4)*mathIndentValue + "px";
                    var wrapperStyle = window.getComputedStyle(wrapper);
                    var wrapperHeight = parseFloat(wrapperStyle.height);
                    wrapper.style.height = "" + (wrapperHeight * newValue) + "px";
                    if(newValue === "1.00"){
                      wrapper.style.cursor = "";
                      wrapper.style.height = "";
                    }
                    else {
                      wrapper.style.cursor = "zoom-in";
                    }
                  }

                }
            }
            };
            shrinkMath();
            window.addEventListener('resize', function() {
              clearTimeout(timeout);
              timeout = setTimeout(shrinkMath, delay);
            });
          });
  }
}
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/MathJax.js?config=TeX-AMS_SVG"></script>
</p>]]></content:encoded>
					
					<wfw:commentRss>https://www.aptech.com/blog/a-guide-to-conducting-cointegration-tests/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
		<item>
		<title>Running publicly available GAUSS code: Part 2</title>
		<link>https://www.aptech.com/blog/running-publicly-available-gauss-code-part-2/</link>
					<comments>https://www.aptech.com/blog/running-publicly-available-gauss-code-part-2/#respond</comments>
		
		<dc:creator><![CDATA[aptech]]></dc:creator>
		<pubDate>Fri, 08 Feb 2019 18:05:00 +0000</pubDate>
				<category><![CDATA[Econometrics]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Video]]></category>
		<category><![CDATA[cointegration]]></category>
		<category><![CDATA[structural breaks]]></category>
		<guid isPermaLink="false">https://www.aptech.com/?p=19462</guid>

					<description><![CDATA[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:

<ul>
<li> Substitute your own dataset.</li>
<li> Modify the indexing commands for your data.</li>
<li>Remove missing values.</li>
<li> Preview your data after loading with the <b>Ctrl+E</b> keyboard shortcut.</li>
</ul>
]]></description>
										<content:encoded><![CDATA[<h3 id="hatemi-code-for-cointegration-with-multiple-structural-breaks">Hatemi code for cointegration with multiple structural breaks</h3>
<p> </p>
<div style="border-style: solid; border-color: #36434c; border-width: 5px;">
<iframe width="800" height="454" src="https://www.youtube.com/embed/covQ86yDbAg" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div>
<br/>
<p>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 <a href="https://ideas.repec.org/c/boc/bocode/g00006.html">Hatemi-J</a> for testing cointegration with multiple <a href="https://www.aptech.com/structural-breaks/">structural breaks</a>. In this video you will learn how to:</p>
<ul>
<li>Substitute your own dataset.</li>
<li>Modify the indexing commands for your data.</li>
<li>Remove missing values.</li>
<li>Preview your data after loading with the <em>Ctrl+E</em> keyboard shortcut.</li>
</ul>
<p><strong>Previous</strong>: <a href="https://www.aptech.com/blog/running-publicly-available-gauss-code-part-1/">Running Public GAUSS Code: Part 1</a></p>
<h2 id="script">Script</h2>
<h3 id="introduction">Introduction</h3>
<p>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 <code>library not found</code> and <code>file not found</code> errors.</p>
<p>Today we will run the code which implements the tests for cointegration with two unknown structural breaks from Dr. Hatemi’s 2008 paper in <em>Empirical Economics</em>,  using a couple of variables from the famous Nelson-Plosser dataset.</p>
<h3 id="starting-point">Starting point</h3>
<p>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. </p>
<h3 id="code-layout">Code layout</h3>
<p>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.</p>
<p>This second section of the code contains all of the procedures that Dr. Hatemi wrote to compute the algorithm from his paper.</p>
<p>The <code>end</code> command on line 22 is the line of demarcation between these two sections.</p>
<p>GAUSS will not run any commands located after <code>end</code>, but it will still find the procedures so they will be available for use by the code in the first section. </p>
<h3 id="data-loading-code">Data loading code</h3>
<p>Let’s look at this first section to see what it is doing. The action starts on line 9 with the <code>load</code> command.</p>
<p>This statement is going to:</p>
<ol>
<li>Look for a file named <code>b22.txt</code> in your current working directory.</li>
<li>Load the data it finds in that fil.</li>
<li>Reshape the data to be a matrix with <code>obs</code> rows and <code>var</code> columns.</li>
</ol>
<p>We’re going to have to change this line because our data is not in <code>b22.txt</code> and we don’t want to have to specify the data size ahead of time, as we see here with <code>obs</code> and <code>var</code>.</p>
<h3 id="our-dataset">Our dataset</h3>
<p>Our data is in a Stata dataset named <code>nelsonplosser.dta</code>. The <code>loadd</code> 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 <code>loadd</code>.</p>
<h3 id="dataset-preview">Dataset preview</h3>
<p>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.</p>
<p>The yellow cells with dots contain missing values. We will deal with those after loading the data.</p>
<p>For this video our dependent variable will be bond yield which is the <code>bnd</code> variable and our independent variable will be the money supply, which is just <code>m</code>.</p>
<h3 id="load-preview-and-index-our-data">Load, preview and index our data</h3>
<p>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’.)</p>
<p>Now we see that lines 10 and 11 are splitting up the variables that we loaded from our dataset.</p>
<p>The intention of line 10 is to select all observations from the first column of <code>z</code>. However, we have a problem because <code>obs</code> has not yet been given a value. We could add a line setting ‘obs’ to be equal to the rows of <code>z</code>. That would be correct. </p>
<p>However, we can replace <code>1:obs</code> with the dot operator. This is shorter and makes it clear that our intention is to load all the rows.</p>
<p>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 <code>z</code> will only have two columns.</p>
<p>The remaining lines create two variables, <code>obs</code> and <code>n</code> which do not seem to be used and then there is the call to main. We see that the only variables passed into <code>main</code> are <code>y</code> and <code>x</code> which we have created.</p>
<p>Let’s add an <code>end</code> command just before the call to <code>main</code> and then run our code so we can verify that our data is loaded correctly.</p>
<p>We’ll open <code>z</code>, <code>y</code> and <code>x</code> in floating symbol editors by clicking on them and using the <code>Ctrl+E</code> hotkey.</p>
<h3 id="remove-missing-values">Remove missing values</h3>
<p>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.</p>
<p>The <code>packr</code> command removes all rows in which any element contains a missing value. If we add <code>packr</code> right after we load the data, the first 40 rows should be trimmed off, leaving us with <code>z</code> as a <code>71x2</code> matrix.</p>
<h3 id="run-the-code-and-view-output">Run the code and view output</h3>
<p>Now that we have confirmed that our data is correct, let’s remove the ‘end’ command that we added and run the full code.</p>
<p>We have successfully run the code. Here is our output.</p>
<h3 id="conclusion">Conclusion</h3>
<p>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!</p>
<h2 id="references">References</h2>
<p>Abdulnasser Hatemi-J, (2008),
<A HREF="https://ideas.repec.org/a/spr/empeco/v35y2008i3p497-505.html">Tests for cointegration with two unknown regime shifts with an application to financial market integration</A>,
<i>Empirical Economics</i>, Springer, vol. 35(3), p. 497-505.</p>
<p>Nelson, Charles and Plosser, Charles, (1982),Trends and random walks in macroeconmic time series: Some evidence and implications, <i>Journal of Monetary Economics</i>, vol. 10(2), p. 139-162.</p>]]></content:encoded>
					
					<wfw:commentRss>https://www.aptech.com/blog/running-publicly-available-gauss-code-part-2/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
