No announcement yet.
  • Filter
  • Time
  • Show
Clear All
new posts

  • Square root of White Variance for hypothesis testing under heteroskedasticity

    Hi all, I'm working on an assignment where I need to test Ho: B2 = 0 against Ha: B2>0. Since there's evidence of heteroskedasticity I've calculated my variance matrix as

    Vw = (X'X)-1X' Sigma-1X(X'X)-1

    However I'm having difficulty getting this defined as a square root so I can use it as my denominator in the calculation (which I need to do by hand and not using any of the hypothesis testing capabilities of Stata). I've tried most every command mentioned on various forums and can't seem to get it right. Is there a set of commands I need to follow so that I can create my denominator?

  • #2
    The Mata function diagonal() extracts the diagonal from a variance-covariance matrix, where the variances are, and sqrt() takes square roots. But first you need to make sure you got the variance matrix right. If X is the model matrix and r the vector of residuals, create a diagonal matrix with the squared residuals using diag(r:^2), usually multiplied by n/(n - p) where n is the number of observations and p is the number of parameters in the model, including the constant. Then apply the sandwich formula (X'X)-1X' Sigma X(X'X)-1

    B = invsym(X'X)                   // outer (bread)
    M = X ' diag(r:^2) * X :* n/(n-p) // inner (meat)
    V = B * M * B                     // var matrix
    sqrt(diagonal(V))                 // robust st errors
    You could try using the regress command with vce(robust) in a small dataset and then apply the above formula to verify that you get the same answer.


    • #3
      Anna Kerkhoff German Rodriguez
      Great explanation and advice by German.
      ​​​​​​​I would use cross() for computing cross-products ( see help mata cross). It is slightly more efficient and avoids computing the diagonal matrix.

      B = invsym(cross(X,X))
      M = cross(X,r:^2,X)* (n/(n-p))
      V = B*M*B


      • #4
        Thank you so much!