title: Computing covariance of pricing errors in r
body: <p>I am trying to compute the covariance matrix of pricing errors as an input to the <strong>Fama-MacBeth joint test statistic</strong> given here.<br>
  I am not sure whether i am doing this correctly and was hoping for some help.</p>
  
  <p>I was gonna post some pictures of those formulas,but i need at least 10 reputation points to post images...so i am gonna use imageur</p>
  
  <p><a href="http://imgur.com/WG6zTL3" rel="nofollow">here</a> is the joint test i am trying to compute :</p>
  
  <p><a href="http://imgur.com/DRpFpM8" rel="nofollow">here</a> is the covariance formula:</p>
  
  <p>My code is as follows</p>
  
  <pre><code>alpha.diff1 &lt;- full.resid-full.mean.resid
  alpha.diff2 &lt;- t(alpha.diff1)
  alpha.sum &lt;- alpha.diff1%*%alpha.diff2
  cov.term &lt;- alpha.sum/(full.num.t^2)
  
  full.joint.test &lt;- t(full.mean.resid)%*%ginv(cov.term)%*%full.mean.resid
  </code></pre>
  
  <p>the variable names are pretty self explanatory i think.</p>
  
  <ul>
  <li><strong>full.num.t</strong> : T in the formulas (total monthly observations)</li>
  <li><strong>full.resid</strong> : Stores the alpha(it) [25 rows of assets,192 columns of monthly errors</li>
  </ul>
  
  <p>the result for the <strong>full.joint.test</strong> variable is <strong>20.86672</strong></p>
  
  <p>Can someone confirm whether i have done this correctly please?</p>