Formula used
The calculator uses the sandwich covariance form:
V = (X'X)-1 X'ΩX (X'X)-1
Here, X is the design matrix. Ω is a diagonal matrix of robust residual weights. For HC0, wi = ei2. For HC1, wi = n / (n - k) times ei2. For HC2, divide by 1 - hi. For HC3, divide by (1 - hi)2. For HC4, divide by (1 - hi)δ, where δ is capped at four.
How to use this calculator
Paste your design matrix into the first box. Include an intercept column if your model used one. Add residuals in the same row order. Add beta estimates when you want robust t statistics. Select the HC option. Press Calculate. The result appears above the form and below the header section. Use CSV for spreadsheet review. Use PDF for a simple saved report.
Example data table
| Observation | Constant | x1 | x2 | Residual |
|---|---|---|---|---|
| 1 | 1 | 2 | 5 | 0.42 |
| 2 | 1 | 3 | 6 | -0.31 |
| 3 | 1 | 4 | 8 | 0.18 |
| 4 | 1 | 6 | 9 | -0.52 |
| 5 | 1 | 8 | 12 | 0.27 |
| 6 | 1 | 9 | 14 | -0.04 |
Understanding the Matrix
A heteroskedastic matrix checks how unequal error variance changes regression uncertainty. Ordinary least squares uses a clean variance pattern. Real data often breaks that pattern. Large observations may carry larger residuals. Small observations may carry smaller residuals. The robust matrix keeps the coefficient estimates unchanged. It changes the estimated uncertainty around those estimates.
Why Robust Estimation Matters
In Mata, the main idea is compact. Build the design matrix. Store residuals as a column vector. Then form a sandwich covariance matrix. The bread is the inverse of X prime X. The meat is X prime Omega X. Omega contains squared residual weights. Different HC choices adjust those weights. HC0 is the base estimate. HC1 adds a sample correction. HC2 and HC3 adjust leverage. HC4 gives stronger protection for influential rows.
Using the Inputs
This calculator accepts a matrix in pasted form. Each row is one observation. Each column is one regressor. Include a constant column when your model has an intercept. Residuals must match the observation count. Optional beta estimates help produce t statistics. Variable names make the output easier to read. The tool also shows leverages, weights, standard errors, and a Mata style command block.
Reading the Results
The covariance matrix is symmetric in most valid cases. Diagonal values should be nonnegative. Their square roots are robust standard errors. Large leverage values deserve attention. They show observations with strong design influence. A tiny denominator can inflate HC2 or HC3 weights. That is useful, but it can also signal unstable data. Check sample size, rank, and scaling before trusting any final report.
Common Checks
Inspect dimensions before calculation. Rows must align with residual entries. Columns must match beta entries when supplied. Watch for perfect collinearity. It makes the inverse fail. Center or scale wide variables when needed. Document the chosen HC option. This makes your regression notes reproducible. It helps analysts repeat your Mata workflow without guessing.
Best Practice
Use this calculator as a transparent audit tool. Compare HC types before publication. Keep the same regressor order everywhere. Save the CSV output for review. Export the PDF when sharing results. For formal work, confirm the final model inside Mata. Use this page to understand every matrix step first.
FAQs
What does this calculator compute?
It computes a heteroskedasticity robust covariance matrix using the sandwich formula. It also shows leverage, residual weights, robust standard errors, and optional t statistics.
Do I need to include an intercept column?
Yes, include a column of ones when your regression used an intercept. The calculator does not add it automatically because the entered matrix should match your model.
Which HC option should I choose?
HC3 is often preferred for smaller samples or influential observations. HC0 is basic. HC1 adds a degrees of freedom correction. Compare results before reporting.
Why did I get a singular matrix warning?
Your design matrix has collinear columns, repeated information, or too few independent rows. Remove redundant columns, check the intercept, and verify the data order.
What are leverage values?
Leverage values measure how strongly each row affects the fitted design. High leverage can inflate HC2, HC3, and HC4 corrections.
Can I paste comma separated rows?
Yes. You can separate row values with spaces or commas. Use a new line or semicolon for the next observation row.
What does the beta vector do?
The beta vector is optional. When supplied, the calculator divides each coefficient by its robust standard error to produce a t statistic.
Is this a replacement for formal regression software?
No. Use it to audit matrix logic, teach the formula, or verify small examples. Confirm final research results inside your statistical workflow.