<?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>cluster-robust &#8211; Aptech</title>
	<atom:link href="https://www.aptech.com/blog/tag/cluster-robust/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.aptech.com</link>
	<description>GAUSS Software - Fastest Platform for Data Analytics</description>
	<lastBuildDate>Thu, 11 Jun 2020 01:34:00 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	
	<item>
		<title>Apples to Apples: The case for cluster-robust standard errors</title>
		<link>https://www.aptech.com/blog/apples-to-apples-the-case-for-cluster-robust-standard-errors/</link>
					<comments>https://www.aptech.com/blog/apples-to-apples-the-case-for-cluster-robust-standard-errors/#respond</comments>
		
		<dc:creator><![CDATA[Eric]]></dc:creator>
		<pubDate>Sat, 08 Dec 2018 14:45:54 +0000</pubDate>
				<category><![CDATA[Econometrics]]></category>
		<category><![CDATA[cluster-robust]]></category>
		<category><![CDATA[covariance]]></category>
		<category><![CDATA[panel data]]></category>
		<guid isPermaLink="false">https://www.aptech.com/?p=18780</guid>

					<description><![CDATA[Linear regression commonly assumes that the error terms of a model are independently and identically distributed (i.i.d)  However, when datasets contain groups, the potential for correlated error terms within groups arises.  In this blog, we explore how to remedy this issue with clustered error terms. ]]></description>
										<content:encoded><![CDATA[<h3 id="introduction">Introduction</h3>
<p><a href="https://www.aptech.com/resources/tutorials/econometrics/linear-regression/">Linear regression</a> commonly assumes that the error terms of a model are independently and identically distributed (<strong>i.i.d</strong>).  However, when datasets contain groups, the potential for correlated error terms within groups arises. </p>
<h2 id="example-weather-shocks-to-apple-orchards">Example: Weather shocks to apple orchards</h2>
<p>For example, consider a model of the supply of apples from various orchards across the United States. Naturally, we would expect that orchards within Washington may all face similar weather-related &quot;shocks&quot; to their supply. However, we would not expect the weather shocks to the orchards in Washington to be the same as the weather shocks to the orchards in New York. </p>
<p><a href="https://www.aptech.com/wp-content/uploads/2018/12/winter-apples.jpg"><img src="https://www.aptech.com/wp-content/uploads/2018/12/winter-apples.jpg" alt="Weather shock to apple production." width="640" height="267" class="aligncenter size-full wp-image-18825" /></a></p>
<p>When these correlated within-group shocks occur, the i.i.d error term assumption is not valid and traditional error terms can result in misleading inference about coefficient estimates. </p>
<p>In these cases, is important to use error terms that appropriately account for the within-group correlation between error terms. </p>
<div class="alert alert-info" role="alert"><strong>Potential impacts of ignoring clustered error terms:</strong> <br><ul><li>Standard errors that are too small</li><li>Confidence interval bands that are too narrow</li><li>Overly large t-statistics</li><li>Over rejection of the null hypothesis</li></ul></div>
<h2 id="the-model">The Model</h2>
<p>Let's consider our hypothetical apple supply model which makes observations for each individual orchard, $i = 1, 2, \ldots\, N$ at each time period $t = 1, 2, \ldots\, T$:</p>
<p>$$y_{it} = x_{it}\beta + u_{it}$$</p>
<p>We can further aggregate our dataset into state-level groups, $g = 1, 2, \ldots, G$ such that:</p>
<p>$$y_{igt} = x_{igt}\beta + u_{igt}$$</p>
<p>The cluster-robust error term assumes that, $u_{igt}$, is correlated within groups but independent across groups. More formally:</p>
<p>$$E[u_{igt}u_{iht}]   \begin{cases} = 0 & \text{ if }g \neq h \\ \neq 0 & \text{ if }g = h \end{cases} $$ </p>
<p>The cluster-robust error computation allows for this correlation:</p>
<p>$$V_{clu}[\hat{\beta}] = (X'X)^{-1} * \sum_{j=1}^G u_j' u_j  * (X'X)^{-1}$$</p>
<p>where</p>
<p>$$u_j = \sum_{cluster_j} u_{it} x_{it} .$$</p>
<h2 id="estimating-our-model-in-gauss">Estimating our model in GAUSS</h2>
<p>Let's look more formally at our apple production model using the <code>apples_cluster.dat</code> dataset. Using this data we will model the production of apples in relationship to orchard acreage:</p>
<p>$$prod = \beta_0 + \beta_1*acres + u$$</p>
<h3 id="estimating-i-i-d-error-terms">Estimating i.i.d error terms</h3>
<p>First, let's model the data using i.i.d standard errors:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Specify filename
fname = __FILE_DIR $+ "apples_cluster.dat";

// Estimate model using ols
struct olsmtOut oOut;
oOut = olsmt(fname, "prod ~ acres", oCtl);</code></pre>
<p>This yields the following results:</p>
<pre>                         Standard                 Prob   Standardized  Cor with
Variable     Estimate      Error      t-value     &gt;|t|     Estimate    Dep Var
-------------------------------------------------------------------------------
CONSTANT    0.0296797   0.0283593     1.04656     0.295       ---         ---
acres         1.03483   0.0285833     36.2041     0.000    0.455813    0.455813 </pre>
<h3 id="estimating-cluster-robust-error-terms">Estimating cluster-robust error terms</h3>
<p>Now, we specify <a href="https://www.aptech.com/releases/gauss19/covariance-computations/">cluster-robust errors</a> using two members in the <code>olsmtControl</code> structure:</p>
<hr />
<dl>
<dt>oCtl.cov</dt>
<dd>String, the type of covariance matrix to be computed:</dd>
</dl>
<ul>
<li><code>"iid"</code> for i.i.d errors.</li>
<li><code>"cluster"</code> for cluster-robust errors.</li>
<li><code>"robust"</code> for the Huber/White sandwich estimator. </li>
</ul>
<dl>
<dt>oCtl.clusterId</dt>
<dd>String, the name of the variable containing data groups.</dd>
</dl>
<hr /> 
<div class="alert alert-info" role="alert"><strong>Note:</strong> Because we are using formula strings to specify our model we use <code>oCtl.clusterId</code> to specify our groups. However, if we use data matrices to specify our model the member <code>oCtl.clusterVar</code> to specify our groups.</div>
<p>Our code for estimation now becomes:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Estimate model using ols
struct olsmtControl oCtl;
oCtl = olsmtControlCreate();

// Set up cluster id variable
oCtl.clusterId = "state";

// Turn on cluster vce
oCtl.cov = "cluster";

// Estimate model 
struct olsmtOut oOut;
oOut = olsmt(fname, "prod ~ acres", oCtl);</code></pre>
<p>Which yields:</p>
<pre>                         Standard                 Prob   Standardized  Cor with
Variable     Estimate      Error      t-value     &gt;|t|     Estimate    Dep Var
-------------------------------------------------------------------------------
CONSTANT    0.0296797   0.0670127    0.442897     0.658       ---         ---
acres         1.03483   0.0505957      20.453     0.000    0.455813    0.455813 </pre>
<h3 id="comparing-results">Comparing results</h3>
<p>There are several key things to note about the two sets of results. </p>
<ol>
<li>Using cluster-robust standard errors has no impact on the coefficient estimates. </li>
<li>The cluster-robust standard errors are larger than i.i.d errors. </li>
</ol>
<p>In this case, the larger standard errors do not impact our conclusions regarding the significance of the estimated coefficients, but this may not always be true.</p>
<h3 id="conclusions">Conclusions</h3>
<p>In today's discussion of <a href="https://www.aptech.com/releases/gauss19/covariance-computations/">cluster-robust standard errors</a> we have learned :</p>
<ol>
<li>What types of models may introduce within-cluster correlation in error terms.</li>
<li>The potential impacts of ignoring within-cluster correlations in error terms.</li>
<li>How to estimate cluster-robust error terms. </li>
</ol>
<p>Code and data from this blog can be found <a href="https://github.com/aptech/gauss_blog/tree/master/econometrics/cluster-robust-12.10.2018">here</a>.</p>
<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/apples-to-apples-the-case-for-cluster-robust-standard-errors/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
