Understanding the VCE: Robust Standard Errors, the Sandwich Estimator and vce(cluster id)

On this page
อ่านฉบับภาษาไทย (Thai version)
Abstract
A regression coefficient and its uncertainty come from two separate calculations, and Stata's vce() option changes only the second. A standard error is not the spread of the data: with variance 18 across 100 hospitals, the standard error of the mean is 0.4243. Stata estimates a variance-covariance matrix, the VCE; standard errors are the square roots of its diagonal, and its covariances are needed for any sum of coefficients. The model-based VCE trusts the model's variance, while the robust sandwich puts the meat, built from squared residuals, between two inverted copies of the bread. Worked by hand for 100 hospitals, an intercept-only Poisson model gives a model-based standard error of 0.0447 and a robust one of 0.0849, with the same coefficient. In modified Poisson regression for a binary outcome, the robust standard error can be the smaller one. This article then contrasts vce(robust) with vce(cluster id), lists what a robust standard error cannot repair, and gives Methods and Results sentences.
Same coefficient, different uncertainty
A research team counts the patients admitted per day in 100 hospitals and fits a Poisson model in Stata with vce(robust), because the last analysis did. A second dataset follows the same patients over several admissions, and its code says vce(cluster patient_id). Many analysts read both options as commands that simply adjust the standard error, without knowing why the adjustment is needed or what happens inside the model.
This article builds the answer from the ground up: variance and the standard error, the variance-covariance estimator (VCE), the model-based and the robust standard error, and the sandwich estimator, then their use in Poisson regression, modified Poisson regression and clustered data.
Why a standard error exists
Suppose we study the number of patients admitted per day in 100 hospitals. Once the data are in, the mean is 5 admissions per day:
$$\bar Y = 5$$A single mean says nothing about how much the hospitals differ from each other.
Take two datasets with the same mean. In dataset A the counts spread little: mean 5, variance 1. In dataset B they spread a lot: mean 5, variance 16. Figure 1, set out as numbers in the table below, shows eight hospitals from each so that the pattern is visible.
If we collected data from another 100 hospitals, the mean estimated from a population like B would change more from sample to sample than one from a population like A, assuming the units are independent and identically distributed within each population. That is the reason a standard error exists.
Figure 1: same mean, different spread
| Dataset | Admissions per day, eight hospitals shown | Mean | Variance |
|---|---|---|---|
| A, little spread | 4, 6, 4, 6, 4, 6, 4, 6 | 5 | 1 |
| B, much spread | 1, 9, 1, 9, 1, 9, 1, 9 | 5 | 16 |
Variance and standard error are different things
A variance describes how spread out the data are. A standard error (SE) describes how uncertain an estimate is over repeated sampling. With $n$ independent observations that each have variance $\sigma^2$, the variance of the mean is
$$Var(\bar Y) = \frac{\sigma^2}{n}$$so its standard error is
$$\boxed{SE(\bar Y) = \sqrt{\frac{\sigma^2}{n}}}$$Suppose the admission counts of 100 hospitals have mean 5 and variance 18. Then
$$SE(\bar Y) = \sqrt{\frac{18}{100}} = 0.4243$$The estimated mean carries a sampling uncertainty of about 0.4243, on the same scale as the admission counts. The value 0.4243 is not the standard deviation of the hospitals; it is the standard error of the estimated mean.
Now keep the variance at 18 but raise the number of hospitals from 100 to 400:
$$SE(\bar Y) = \sqrt{\frac{18}{400}} = 0.2121$$The standard error falls by about half, because the number of observations rose fourfold. The sample size and the spread of the data both drive the standard error, and the two have to be kept apart.
What a VCE is
VCE stands for variance-covariance estimator: the method used to estimate the variances and covariances of the statistical estimates. When we write in Stata
poisson admissions treatment age, vce(robust)the option vce(robust) means: use the robust variance-covariance estimator to estimate the uncertainty of the regression coefficients [1].
What Stata computes is not one standard error. It is the variance-covariance matrix of all the regression coefficients.
Why it has to be a matrix
Take a regression model
$$g\big(E(Y_i \mid X_i)\big) = \beta_0 + \beta_1 X_i$$where $\beta_0$ is the intercept and $\beta_1$ the regression coefficient of $X$. The analysis gives the estimates
$$\hat{\boldsymbol\beta} = \begin{pmatrix} \hat\beta_0 \\ \hat\beta_1 \end{pmatrix}$$Each estimate has its own uncertainty, and the two may also change together when the data are sampled again. The VCE therefore has to estimate a matrix of this shape:
$$\boxed{\widehat V = \begin{pmatrix} \widehat{Var}(\hat\beta_0) & \widehat{Cov}(\hat\beta_0, \hat\beta_1) \\ \widehat{Cov}(\hat\beta_1, \hat\beta_0) & \widehat{Var}(\hat\beta_1) \end{pmatrix}}$$| Position | Meaning |
|---|---|
| Top left | Estimated variance of $\hat\beta_0$ |
| Bottom right | Estimated variance of $\hat\beta_1$ |
| Off the diagonal | Estimated covariance between the two coefficients |
From a VCE to standard errors
Suppose a regression gives this estimated VCE:
$$\widehat V = \begin{pmatrix} 0.040 & -0.010 \\ -0.010 & 0.010 \end{pmatrix}$$The standard errors are found by taking the square roots of the values on the diagonal.
-
Standard error of the intercept
\[ SE(\hat\beta_0) = \sqrt{0.040} = 0.20 \]
The top-left entry is the variance of the intercept.
-
Standard error of the coefficient
\[ SE(\hat\beta_1) = \sqrt{0.010} = 0.10 \]
The bottom-right entry is the variance of the coefficient of X.
-
The general rule
\[ \boxed{SE(\hat\beta_j) = \sqrt{\widehat V_{jj}}} \]
Each standard error is the square root of its own diagonal entry; the off-diagonal entries are not used for it.
Result: The standard errors are 0.20 for the intercept and 0.10 for the coefficient: the square roots of the diagonal of the VCE.
Why the covariance has to be kept
Suppose we want the sum of the two coefficients, $\hat\theta = \hat\beta_0 + \hat\beta_1$. The variance of a sum is not just the two variances added: the covariance enters too.
-
The variance of a sum
\[ Var(\hat\theta) = Var(\hat\beta_0) + Var(\hat\beta_1) + 2Cov(\hat\beta_0, \hat\beta_1) \]
The covariance term appears twice.
-
Values from the matrix above
\[ = 0.040 + 0.010 + 2(-0.010) = 0.030 \]
The negative covariance makes the sum less variable than the two variances alone suggest.
-
Standard error of the sum
\[ SE(\hat\theta) = \sqrt{0.030} = 0.1732 \]
The square root of the variance of the sum.
Result: The standard error of the sum is 0.1732.
With only the separate standard errors of the two coefficients and no covariance, this standard error cannot be computed correctly. That is why Stata keeps the whole matrix and not only the standard errors.
Where the VCE lives in Stata
After a regression model is fitted, Stata stores the main results in the objects listed in the table below. They can be displayed with
matrix list e(b)
matrix list e(V)
estat vceIf the model has 4 coefficients including the intercept, e(b) is 1 × 4 and e(V) is 4 × 4. This is the standard structure of Stata estimation results [1].
| Stata object | Meaning |
|---|---|
e(b) | Vector of estimated coefficients |
e(V) | Estimated variance-covariance matrix |
_b[varname] | Estimated coefficient of the named variable |
_se[varname] | Estimated standard error of that coefficient |
estat vce | Displays the variance-covariance matrix |
How the VCE changes the confidence interval and the P value
Suppose a regression gives $\hat\beta_1 = 0.40$ with a standard error of 0.10. A Wald 95% confidence interval on the coefficient scale, by the normal approximation, is
$$95\%\ CI = \hat\beta_1 \pm 1.96\,SE(\hat\beta_1)$$$$= 0.40 \pm 1.96(0.10)$$$$\boxed{95\%\ CI = (0.204,\ 0.596)}$$Now switch to a robust VCE. The standard error becomes 0.19, while the coefficient is still 0.40:
$$95\%\ CI = 0.40 \pm 1.96(0.19)$$$$\boxed{95\%\ CI = (0.028,\ 0.772)}$$Figure 2: the same coefficient, two intervals
| Result | Model-based | Robust |
|---|---|---|
| Coefficient | 0.40 | 0.40 |
| Standard error | 0.10 | 0.19 |
| 95% CI | 0.204 to 0.596 | 0.028 to 0.772 |
| Wald $z = \hat\beta / SE$ | 4.00 | 2.11 |
| Two-sided P value, approximately | 0.00006 | 0.035 |
The model-based VCE
Any regression software needs a way to estimate the variance of the coefficients. The standard method in maximum likelihood estimation is the model-based VCE, which uses the likelihood and the model's own assumptions; its square roots are the model-based standard errors. In many models it is estimated as the inverse of the observed information matrix, the negative Hessian:
$$\boxed{\widehat V_{\text{model}} = A^{-1}}$$where
$$A = -\frac{\partial^2 \ell(\boldsymbol\beta)}{\partial\boldsymbol\beta\,\partial\boldsymbol\beta^{\top}}\bigg|_{\boldsymbol\beta = \hat{\boldsymbol\beta}}$$This is the formula of the observed-information VCE, not a formula that can stand in for every kind of VCE.
To make it intuitive, think of the Hessian as telling how quickly the likelihood changes when the regression coefficient changes. If the likelihood is strongly curved around the estimate, the coefficient is usually pinned down fairly precisely. If the likelihood is rather flat, the estimate of the coefficient is more uncertain.
The example of Poisson regression
Suppose we fit a Poisson regression model,
$$Y_i \mid X_i \sim \text{Poisson}(\mu_i)$$with
$$\log(\mu_i) = X_i^{\top}\boldsymbol\beta$$or, equivalently, $\mu_i = \exp(X_i^{\top}\boldsymbol\beta)$. The Poisson distribution has one key property:
$$\boxed{Var(Y_i \mid X_i) = E(Y_i \mid X_i) = \mu_i}$$The conditional variance equals the conditional mean. If the model expects a hospital to have 5 admissions on average, $E(Y_i \mid X_i) = 5$, the Poisson model also uses $Var(Y_i \mid X_i) = 5$ when it computes the model-based uncertainty.
What if the real variance is 18?
Now suppose the conditional variance is higher than the mean the Poisson assumption implies:
$$Var(Y_i \mid X_i) = 18 > 5$$This is called overdispersion. When the Poisson model uses a variance of 5 but the real variability is higher, the model-based standard error can understate the uncertainty.
One caution. Comparing the mean and the variance of the whole dataset does not yet prove conditional overdispersion when the model has several predictors, because differences in the mean between groups also raise the overall variance. What has to be assessed is the variance conditional on the predictors in the model.
The robust VCE
A robust VCE estimates the variance-covariance matrix while relying less on some of the model's assumptions, above all the assumption about the variance. The most widely used version is the Huber-White sandwich variance estimator, and its square roots are the robust (sandwich) standard errors [2].
In Poisson regression, if the conditional mean model is right but the conditional variance does not follow the Poisson distribution, the regression coefficients can still be estimated with the Poisson estimating equations, and the robust VCE can be used for statistical inference. This idea is the basis of Poisson pseudo-maximum likelihood and of modified Poisson regression.
Model-based and robust VCE compared
| Point | Model-based Poisson VCE | Robust VCE |
|---|---|---|
| What it estimates | The variance of the coefficients | The variance of the coefficients |
| Same coefficient? | Yes | Yes |
| Relies on $Var(Y \mid X) = \mu$? | Yes | Not needed |
| Uses residual or score information? | Uses the model's information | Also uses the empirical score contributions |
| Handles a misspecified variance? | Limited | Yes, under suitable conditions |
| Handles correlated observations automatically? | No | No: consider a cluster-robust VCE or another method |
How the sandwich estimator is computed
Once it is clear that the variance of the coefficients has to be estimated, the next step is how. The sandwich estimator has the basic formula
$$\boxed{\widehat{Var}_{\text{robust}}(\hat{\boldsymbol\beta}) = A^{-1} B A^{-1}}$$This is the basic form for independent observations, without any finite-sample correction. It is called a sandwich because it has three parts:
- Bread, $A^{-1}$, on the left
- Meat, $B$, in the middle
- Bread, $A^{-1}$, on the right
What the bread is
For Poisson regression with a log link,
$$A = \sum_{i=1}^{n} \hat\mu_i X_i X_i^{\top}$$where $X_i$ is the vector of predictors, including the intercept. The bread links the variability of the estimating equations to the variability of the estimated coefficients: it reflects how sensitive the equations used to estimate a coefficient are to a change in that coefficient.
What the meat is
First comes the score contribution of each observation. For Poisson regression it is
$$s_i = X_i(Y_i - \hat\mu_i)$$where $Y_i - \hat\mu_i$ is the raw residual, the difference between the observed value and the value the model predicts. The score contributions of all observations then build the meat:
$$B = \sum_{i=1}^{n} s_i s_i^{\top}$$Substituting the Poisson score gives
$$\boxed{B = \sum_{i=1}^{n} X_i X_i^{\top}(Y_i - \hat\mu_i)^2}$$The formula uses each observation's squared residual. When the data vary a lot, the score contributions carry that variability into the meat.
Why the model-based and robust VCE differ
If the Poisson variance assumption is right,
$$E\big((Y_i - \mu_i)^2 \mid X_i\big) = \mu_i$$so in expectation the meat agrees with the bread:
$$E(B \mid X) \approx A$$The sandwich VCE is then close to
$$A^{-1} A A^{-1} = A^{-1}$$which is the model-based VCE. But if the conditional variance does not follow the Poisson assumption,
$$E\big((Y_i - \mu_i)^2 \mid X_i\big) \ne \mu_i$$the meat and the bread no longer need to be equal, and so
$$A^{-1} B A^{-1} \ne A^{-1}$$This is the mathematical reason the robust standard error differs from the model-based one. Stata uses the Huber-White sandwich in vce(robust) and extends the same idea to the cluster-robust VCE.
Worked example: the robust standard error by hand
| Admissions per day ($Y$) | Number of hospitals | $n_Y(Y - 5)^2$ |
|---|---|---|
| 0 | 20 | 500 |
| 1 | 25 | 400 |
| 5 | 10 | 0 |
| 9 | 25 | 400 |
| 10 | 20 | 500 |
| Total | 100 | 1,800 |
Five steps from the table to two standard errors
The model is an intercept-only Poisson model, so every observation has $X_i = 1$, and the bread and the meat are single numbers.
-
Step 1. The mean
\[ \bar Y = \frac{\sum_i Y_i}{n} = 5 \]
The sum is 20(0) + 25(1) + 10(5) + 25(9) + 20(10), divided by 100 hospitals.
-
Step 2. The empirical variance
\[ \hat\sigma^2_{\text{empirical}} = \frac{1800}{100} = 18 \]
To match the sandwich formula before any small-sample correction, the variance is divided by n. The usual sample variance divides by n - 1 and gives 1800/99 = 18.1818, so the variance Stata prints after summarize may not be exactly 18.
-
Step 3. Fit the intercept-only Poisson model
\[ \hat\beta_0 = \log(5) = 1.6094 \]
The model is log(mu_i) = beta_0. With only an intercept, the fitted mean is 5 for every hospital.
-
Step 4a. The bread
\[ A = \sum_{i=1}^{n} \hat\mu_i = 100(5) = 500 \]
For the intercept-only Poisson model the bread is the sum of the fitted means.
-
Step 4b. The model-based VCE
\[ \widehat V_{\text{model}} = \frac{1}{500} = 0.002 \]
The model-based VCE is the inverse of the bread.
-
Step 4c. The model-based standard error
\[ SE_{\text{model}} = \sqrt{0.002} = 0.0447 \]
Take the square root.
-
Step 5a. The meat
\[ B = \sum_{i=1}^{n} (Y_i - \hat\mu)^2 = 1800 \]
With X_i = 1 the meat reduces to the sum of squared residuals, the total of the last column of the table.
-
Step 5b. The sandwich VCE
\[ \widehat V_{\text{robust}} = \frac{B}{A^2} = \frac{1800}{500^2} = 0.0072 \]
Bread, meat, bread: A^-1 B A^-1 with single numbers.
-
Step 5c. The robust standard error
\[ SE_{\text{robust}} = \sqrt{0.0072} = 0.0849 \]
Take the square root.
-
Check the ratio
\[ \frac{SE_{\text{robust}}}{SE_{\text{model}}} = \sqrt{\frac{18}{5}} \approx 1.90 \]
The robust standard error is about 1.90 times the model-based one: the real variance, 18, against the variance of 5 the Poisson model assumes.
Result: Model-based standard error 0.0447, robust standard error 0.0849. Both methods keep the coefficient at 1.6094; what changes is the estimated variance of that coefficient, from 0.002 to 0.0072.
0.0849 is the uncorrected sandwich standard error, used here to show the arithmetic. Stata may apply an extra finite-sample multiplier: in this intercept-only example the multiplier 100/99 raises the standard error to about 0.0853. The difference does not come from a change of model; it comes from adjusting the variance estimator for a limited sample size.
Reproducing the hand example in Stata
The same dataset can be built and analysed in Stata without any real patient data. These are the hand example's commands:
* Create synthetic admission count data
clear
input admissions frequency
0 20
1 25
5 10
9 25
10 20
end
* Expand to 100 independent observations
expand frequency
drop frequency
* Examine the data
count
summarize admissions, detail
* Model 1: Conventional Poisson
poisson admissions
estimates store poisson_model
display "Coefficient = " _b[_cons]
display "Model-based SE = " _se[_cons]
* Model 2: Robust Poisson
poisson admissions, vce(robust)
estimates store poisson_robust
display "Coefficient = " _b[_cons]
display "Robust SE = " _se[_cons]
* Inspect coefficients and VCE
matrix list e(b)
matrix list e(V)
estat vce
* Compare the two models
estimates table poisson_model poisson_robust, b seAfter the run, look for the results in the table below.
| Result | Ordinary Poisson | Robust Poisson |
|---|---|---|
| Estimated log mean | 1.6094 | 1.6094 |
| Standard error, approximately | 0.0447 | 0.0853 |
| VCE method | Model-based | Sandwich |
| Predicted mean | 5 | 5 |
Stata: the 100 hospitals, model-based and robust
poisson admissions if volatile == `g', nolog
scalar sc_b = _b[_cons]
scalar sc_sm = _se[_cons]
canon `k'.b0 4 _b[_cons]
canon `k'.se_model 4 _se[_cons]
predict double mu if volatile == `g', n
generate double r2 = (admissions - mu)^2 if volatile == `g'
matrix accum J = one if volatile == `g' [iweight = mu], noconstant
matrix accum K = one if volatile == `g' [iweight = r2], noconstant
matrix Ji = invsym(J)
matrix V = Ji*K*Ji
canon `k'.bread 4 el(J, 1, 1)
canon `k'.meat 4 el(K, 1, 1)
canon `k'.v_model 6 el(Ji, 1, 1)
canon `k'.v_hc0 6 el(V, 1, 1)
canon `k'.se_hc0 4 sqrt(el(V, 1, 1))
canon `k'.ratio_hc0_model 4 sqrt(el(V, 1, 1))/scalar(sc_sm)
poisson admissions if volatile == `g', vce(robust) nolog
Poisson regression Number of obs = 100
LR chi2(0) = 0.00
Prob > chi2 = .
Log likelihood = -365.2899 Pseudo R2 = 0.0000
------------------------------------------------------------------------------
admissions | Coefficient Std. err. z P>|z| [95% conf. interval]
-------------+----------------------------------------------------------------
_cons | 1.609438 .0447214 35.99 0.000 1.521786 1.69709
------------------------------------------------------------------------------
CANON g1.volatile.b0 1.6094
CANON g1.volatile.se_model 0.0447
(100 missing values generated)
(100 missing values generated)
(obs=500)
(obs=1800)
CANON g1.volatile.bread 500.0000
CANON g1.volatile.meat 1800.0000
CANON g1.volatile.v_model 0.002000
CANON g1.volatile.v_hc0 0.007200
CANON g1.volatile.se_hc0 0.0849
CANON g1.volatile.ratio_hc0_model 1.8974
Poisson regression Number of obs = 100
Wald chi2(0) = .
Prob > chi2 = .
Log pseudolikelihood = -365.2899 Pseudo R2 = 0.0000
------------------------------------------------------------------------------
| Robust
admissions | Coefficient std. err. z P>|z| [95% conf. interval]
-------------+----------------------------------------------------------------
_cons | 1.609438 .0852803 18.87 0.000 1.442292 1.776584
------------------------------------------------------------------------------
(obs=500) is the bread A and (obs=1800) the meat B. The second table uses vce(robust): the same coefficient, with standard error 0.0853, the hand value 0.0849 after the 100/99 multiplier. Lines beginning CANON echo each result; read the number at the end of the line.Modified Poisson regression: why it needs the robust standard error
A second application matters a great deal in clinical epidemiology: estimating a risk ratio (RR) from a binary outcome with modified Poisson regression, a log-link Poisson model fitted to a 0 or 1 outcome. Suppose we study the association between inadequate antenatal care (ANC) and neonatal morbidity within 28 days. The outcome is binary:
$$Y_i = \begin{cases} 1 & \text{morbidity} \\ 0 & \text{no morbidity} \end{cases}$$What variance does a binary outcome have?
For a binary outcome with event probability $p$,
$$E(Y) = p$$but its variance, the Bernoulli variance, is
$$\boxed{Var(Y) = p(1 - p)}$$unlike the Poisson model, which sets $Var(Y) = p$. Take a risk of 0.40:
| Distribution | Mean | Variance |
|---|---|---|
| Bernoulli | 0.40 | 0.24 |
| Poisson working variance | 0.40 | 0.40 |
A risk ratio from binary data
| ANC | Morbidity | No morbidity | Total |
|---|---|---|---|
| Inadequate | 40 | 60 | 100 |
| Adequate | 20 | 80 | 100 |
The risks, the risk ratio and the odds ratio
-
Risk after inadequate ANC
\[ p_1 = \frac{40}{100} = 0.40 \]
40 of the 100 infants had morbidity.
-
Risk after adequate ANC
\[ p_0 = \frac{20}{100} = 0.20 \]
20 of the 100 infants had morbidity.
-
Risk ratio
\[ \boxed{RR = \frac{0.40}{0.20} = 2.00} \]
The ratio of the two risks.
-
Odds ratio
\[ \boxed{OR = \frac{40/60}{20/80} = 2.67} \]
The ratio of the two odds, for contrast.
Result: RR 2.00 and OR 2.67: the risk ratio and the odds ratio are not the same value.
Model-based and robust standard errors of the log risk ratio
With only a binary exposure and independent observations, both standard errors of the log risk ratio have closed forms.
-
Poisson model-based standard error
\[ SE_{\text{Poisson}}(\log RR) = \sqrt{\frac{1}{40} + \frac{1}{20}} \]
One over each group's number of events.
-
Its value
\[ \boxed{SE_{\text{Poisson}} = 0.2739} \]
This trusts the Poisson variance, p.
-
Robust standard error, the formula
\[ SE_{\text{robust}}(\log RR) \approx \sqrt{\frac{1 - p_1}{n_1 p_1} + \frac{1 - p_0}{n_0 p_0}} \]
The formula for a binary risk ratio.
-
Substitute the risks
\[ = \sqrt{\frac{0.60}{100(0.40)} + \frac{0.80}{100(0.20)}} \]
p1 = 0.40 and p0 = 0.20, with 100 infants in each group.
-
Add the two terms
\[ = \sqrt{0.015 + 0.040} \]
The two terms of the sum.
-
Its value
\[ \boxed{SE_{\text{robust}} = 0.2345} \]
This time the robust standard error is smaller than the model-based 0.2739.
-
Robust 95% confidence interval
\[ 95\%\ CI_{RR} = \exp\big(\log(2) \pm 1.96(0.2345)\big) \]
Built on the log scale and exponentiated.
Result: RR 2.00, 95% CI 1.26 to 3.17 with the robust standard error. Here the robust standard error, 0.2345, is smaller than the Poisson model-based 0.2739.
This shows that a robust standard error is not necessarily higher than the conventional one. In this binary example the Bernoulli variance is below the Poisson working variance, so the sandwich shrinks the standard error. All values are hypothetical, not results of a real study.
The Stata command for modified Poisson
* Binary outcome: 0 = No morbidity, 1 = Morbidity
* Independent observations
poisson morbidity28 i.inadequate_anc ///
i.age_group i.low_ses i.coverage_gap, ///
irr vce(robust)Stata heads the table IRR, its label for an incidence rate ratio, because the command is poisson, irr. But when the outcome is binary and the model estimates the risk within one follow-up horizon, with no person-time offset, $\exp(\hat\beta)$ is read as a risk ratio under a log-risk mean model. The IRR label Stata prints does not turn the estimate into an incidence rate ratio.
Adding exposure(tmorbidity28) to use person-time as the denominator changes the mean model into a rate model, and the effect measure has to be interpreted anew.
One more caution: a log-link risk model can predict probabilities above 1 for some covariate profiles. A robust standard error does not fix that.
vce(robust) or vce(cluster patient_id)?
Up to here every observation was assumed independent of the others. Many kinds of clinical data are not. Suppose we study the hospital admissions of 100 patients, each followed over several periods. Observations from the same patient may be related to each other.
Plain vce(robust) treats every row as an independent observation, so it may misjudge the uncertainty. The cluster-robust VCE, and the cluster-robust standard error it gives, is what has to be considered.
How the cluster-robust VCE works
In the ordinary robust VCE the meat uses the score contribution of each observation:
$$B_{\text{robust}} = \sum_{i=1}^{n} s_i s_i^{\top}$$When there are several patients and each has several rows, the score contributions within the same patient are added together first. Let $g$ be a cluster, here a patient:
$$S_g = \sum_{i \in g} s_i$$The cluster-level meat is then built from these sums:
$$\boxed{B_{\text{cluster}} = \sum_{g=1}^{G} S_g S_g^{\top}}$$which gives
$$\widehat V_{\text{cluster}} = A^{-1} B_{\text{cluster}} A^{-1}$$with the finite-sample corrections not shown. This lets observations within a cluster be correlated, under two key conditions: the clusters must be independent of each other, and there must in general be enough independent clusters [5]. The same approach has been applied to modified Poisson regression for correlated binary outcomes [4].
The Stata code
* Independent observations
poisson admissions i.treatment c.age, vce(robust)
* Repeated observations within each patient
poisson admissions i.treatment c.age, ///
vce(cluster patient_id)vce(cluster patient_id) does not make the software build matched pairs, fix confounding or add patient fixed effects. It changes how the variance is estimated, by using the cluster as the independent unit when the score variability is computed.
With few clusters, the standard cluster-robust standard error may give confidence intervals and P values that cannot be trusted. Small-sample adjustments, or a method of inference suited to the number of clusters, then have to be considered.
The kinds of VCE in Stata
Stata supports several kinds of VCE; which ones are available depends on the estimation command [1].
| VCE option | How it works | When to use it |
|---|---|---|
vce(oim) | Inverse of the observed information matrix | The likelihood's variance assumptions are appropriate |
vce(opg) | Inverse of the outer product of the gradients | A model-based alternative under the information equality |
vce(robust) | Sandwich VCE | A misspecified variance has to be allowed for, with independent observations |
vce(cluster id) | Cluster-robust sandwich VCE | Observations may be correlated within a cluster |
vce(bootstrap) | Sampling variability estimated by resampling | A bootstrap VCE is wanted, resampling as the design requires |
vce(jackknife) | Variance estimated by leaving out one unit at a time | The jackknife suits the estimator and the design |
OPG, bootstrap and jackknife
vce(opg) is not the robust sandwich VCE, even though it also uses score information, because the robust sandwich uses both the bread and the meat.
vce(bootstrap) and vce(jackknife) are not better than a robust standard error in every case. With clustered data, the resampling unit has to match the design of the study.
Decision table for clinical research
| Research question or data structure | Method to consider |
|---|---|
| Count outcome, independent patients | Poisson model-based or robust VCE, according to the variance assumption and the aim of the inference |
| Count outcome with overdispersion | Poisson with a robust VCE, or negative binomial regression, according to the aim of the analysis |
| Binary outcome, RR wanted | Modified Poisson with a robust VCE |
| Repeated observations per patient | Cluster-robust VCE, or a suitable longitudinal model |
| Patients sampled from several hospitals | Consider the cluster structure created by the study design |
| Complex survey sampling | Survey-design-based VCE through svy |
| Very few clusters | Small-sample-adjusted inference, or another method suited to the model |
What a robust standard error cannot do
This point needs to be clear, because a robust standard error is easy to use for the wrong purpose. The table sets out which problems it can and cannot solve.
| Problem | Does a robust SE solve it? | Reason |
|---|---|---|
| Conditional variance does not match the model | Yes, under conditions | The sandwich VCE estimates it |
| Heteroskedasticity | Yes, under conditions | No constant variance has to be assumed |
| Correlation within a patient | Not plain robust | Consider a cluster-robust VCE |
| Wrong conditional mean model | No | The coefficient may not estimate the value wanted |
| Unmeasured confounding | No | It is a problem of bias, not only of the SE |
| Selection bias | No | A VCE does not correct sampling bias |
| Missing data bias | No | It does not correct the missingness mechanism |
| Small-sample bias | Not guaranteed | The sandwich rests on large-sample asymptotics |
| Excess zeros or a wrong count distribution | Not directly | The data-generating mechanism and the model fit have to be assessed |
A robust standard error does not make the model right
Suppose the true conditional mean is
$$E(Y \mid X) = \exp(\beta_0 + \beta_1 X + \beta_2 X^2)$$but we fit a model without $X^2$:
$$E(Y \mid X) = \exp(\beta_0 + \beta_1 X)$$Even with
poisson outcome x, vce(robust)we still cannot conclude that the coefficient of $X$ is the right value for the relationship in the true model. The robust VCE may give the uncertainty of a pseudo-true coefficient, the value a misspecified model converges to, but that does not automatically make the coefficient the clinical parameter or the causal effect we want.
In the same way, fitting modified Poisson regression to a case-control sample, in which cases and controls were sampled in proportions that do not reflect the source population, and reporting an RR without regard to the sampling design is not fixed by adding vce(robust). The article on control sampling shows how the design decides the measure.
Robust Poisson or negative binomial?
For a count outcome with overdispersion, both robust Poisson and negative binomial regression can be used, but the two do not have the same aim in every case.
Robust Poisson sets the conditional mean
$$E(Y_i \mid X_i) = \exp(X_i^{\top}\boldsymbol\beta)$$and uses the sandwich VCE, without needing the Poisson variance to be right. If the conditional mean is right and the independence assumptions are suitable, Poisson pseudo-maximum likelihood gives consistent coefficient estimates even when the conditional variance differs from the conditional mean.
Negative binomial regression is another model, one that sets an explicit mean-variance relationship, such as the NB2 form
$$Var(Y_i \mid X_i) = \mu_i + \alpha\mu_i^2$$where $\alpha$ is the overdispersion parameter [6]. If the negative binomial distribution and variance structure fit, the model may be more efficient for some parameters, and it is useful for simulating or predicting the count distribution. That does not make it better than robust Poisson every time.
Choose from the aim of the study, the adequacy of the mean model and the distribution assumptions, not from the finding of overdispersion alone. The article on Poisson rates covers the count models themselves.
Reporting the results
Methods, modified Poisson regression:
Adjusted risk ratios and 95% confidence intervals were estimated using modified Poisson regression with a log link and robust sandwich variance estimation. The analysis assumed independent observations and a correctly specified conditional mean model.
If the data are clustered within hospitals and a cluster-robust VCE was actually used, the sentence changes to:
Adjusted risk ratios and 95% confidence intervals were estimated using modified Poisson regression with a log link and cluster-robust sandwich variance estimation, accounting for within-hospital correlation.
The two sentences mean different things and should not be swapped without checking the study design.
Results: suppose the analysis gave $aRR = 2.00$, 95% CI 1.26 to 3.17. It can be reported as:
Inadequate antenatal care was associated with a higher risk of neonatal morbidity within 28 days (adjusted RR 2.00, 95% CI 1.26 to 3.17).
These numbers are an example for writing only, not the result of analysing a real dataset. A manuscript must use the numbers of the adjusted model that was actually run.
Summary: what has to be understood
| Concept | What to remember |
|---|---|
| Variance of the outcome | The spread of the data $Y$ |
| Sampling variance | The variability of an estimate over repeated sampling |
| VCE | The method that estimates the variance-covariance matrix of the estimated parameters |
| Standard error | The square root of the estimated variance of a coefficient |
| Model-based VCE | Uses information from the model and relies on the model's assumptions |
| Robust VCE | Uses the sandwich approach to allow for some forms of variance misspecification |
| Cluster-robust VCE | Adds the score contributions within each cluster before computing the meat |
| Modified Poisson | A Poisson log-link estimating model for a binary outcome, to estimate an RR with a robust VCE |
| Negative binomial | A count distribution whose variance can exceed the mean through a dispersion parameter |
Common misreadings and their fixes
-
"vce(robust) is just a command that adjusts the standard error."
It chooses how the whole variance-covariance matrix of the coefficients is estimated; the standard errors, intervals and P values follow from that matrix.
Fix: Read vce() as a choice of variance-covariance estimator, made for a reason: the variance assumption or the independence structure.
-
"The covariance in the VCE is the covariance between two predictors."
It is the covariance between the estimates of two coefficients over repeated sampling.
Fix: Use it for any sum or contrast of coefficients; the variance of a sum includes twice the covariance.
-
"A robust standard error is always larger."
In the binary example the robust standard error of the log risk ratio is 0.2345, smaller than the Poisson model-based 0.2739.
Fix: Expect either direction: the sandwich follows the real variance, which can be above or below what the model assumes.
-
"Modified Poisson needs the sandwich because of overdispersion."
For a risk of 0.40 the Bernoulli variance is 0.24, below the Poisson working variance of 0.40.
Fix: The sandwich is needed because the Poisson variance assumption does not fit binary data.
-
"The overall mean and variance prove overdispersion."
Differences in the mean between groups also raise the overall variance.
Fix: Judge the variance conditional on the predictors in the model.
-
"vce(cluster patient_id) pairs or adjusts the patients."
It does not build matched pairs, fix confounding or add patient fixed effects.
Fix: Treat it as a change in the variance estimator only: the cluster becomes the independent unit for the score variability.
-
"vce(opg) is the sandwich, and the bootstrap is always better."
OPG uses score information but not the bread and meat together; resampling is not better in every case.
Fix: Use vce(robust) or vce(cluster id) for the sandwich, and resample the unit the design sampled.
-
"Stata says IRR, so it is an incidence rate ratio."
With a binary outcome, one follow-up horizon and no person-time offset, the exponentiated coefficient is a risk ratio.
Fix: Name the measure from the outcome and the model, not from the column label.
-
"Negative binomial is always better than robust Poisson."
It may be more efficient when its distribution fits, but it answers a different aim.
Fix: Choose from the aim of the study and the mean model, not from the finding of overdispersion alone.
Glossary
- variance-covariance matrix (VCE) (เมทริกซ์ความแปรปรวนและความแปรปรวนร่วม)
- The matrix of the estimated variances of the coefficients on its diagonal and their covariances off it; Stata's vce() option chooses how it is estimated, and standard errors are the square roots of its diagonal.
- model-based standard error (standard error แบบอิงแบบจำลอง)
- The standard error from the model-based VCE, which relies on the model's own variance assumption; in maximum likelihood often the inverse of the observed information.
- observed information matrix (OIM)
- The negative Hessian of the log-likelihood at the estimate; its inverse is the model-based VCE that vce(oim) reports.
- Poisson regression
- A model for counts in which the log of the mean is linear in the predictors and the conditional variance equals the conditional mean.
- overdispersion (การกระจายเกินกว่าที่แบบจำลองกำหนด)
- A conditional variance higher than the mean the Poisson model assumes; the model-based standard error may then be too small.
- robust (sandwich) standard error (ค่าคลาดเคลื่อนมาตรฐานแบบแซนด์วิช)
- The standard error from the Huber-White sandwich VCE; it allows the variance assumption to be wrong when the mean model is right and observations are independent.
- sandwich estimator
- The variance formula A^-1 B A^-1: the meat B between two copies of the inverted bread A.
- bread (ส่วน bread ของ sandwich estimator)
- A, for Poisson regression the sum of the fitted means times X_i X_i'; it links the variability of the estimating equations to that of the coefficients.
- meat (ส่วน meat ของ sandwich estimator)
- B, the sum of s_i s_i', which for Poisson regression is the sum of X_i X_i' times each squared residual.
- score contribution (score contribution ของแต่ละหน่วยสังเกต)
- One observation's share of the estimating equation, s_i; for Poisson regression X_i times the raw residual Y_i minus the fitted mean.
- modified Poisson regression (Poisson ดัดแปลง)
- A log-link Poisson model fitted to a 0 or 1 outcome with a robust VCE, to estimate a risk ratio.
- Bernoulli variance (ความแปรปรวนแบบ Bernoulli)
- The variance of a binary outcome with probability p, p(1 - p), lower than the Poisson working variance p.
- incidence rate ratio
- The ratio of two event rates; the label Stata prints after poisson, irr whatever the outcome is.
- cluster-robust standard error
- A sandwich standard error whose meat adds the score contributions within each cluster before squaring; it needs independent clusters and enough of them.
- outer product of the gradients (OPG)
- A model-based VCE from the score information alone; it is not the robust sandwich, which uses both bread and meat.
- pseudo-true coefficient
- The value a misspecified model's coefficient converges to; a robust VCE can describe its uncertainty without making it the parameter wanted.
- negative binomial regression
- A count model with an explicit mean-variance relation, such as NB2, Var = mu + alpha mu^2, with alpha the overdispersion parameter.
References
- StataCorp. Stata Base Reference Manual: [R] vce_option. Stata documentation at stata.com (PDF); release and year not stated. Accessed 2026-10-11. https://www.stata.com/manuals/rvce_option.pdf
- StataCorp. Stata User's Guide: [U] 20.22, Obtaining robust variance estimates. Stata documentation at stata.com (PDF); release and year not stated. Accessed 2026-10-11. https://www.stata.com/manuals/u20.pdf
- Zou G. A modified Poisson regression approach to prospective studies with binary data. Am J Epidemiol. 2004;159(7):702-706. doi:10.1093/aje/kwh090 https://doi.org/10.1093/aje/kwh090
- Zou GY, Donner A. Extension of the modified Poisson regression model to prospective studies with correlated binary data. Stat Methods Med Res. 2013;22(6):661-670. doi:10.1177/0962280211427759 https://doi.org/10.1177/0962280211427759
- Liang KY, Zeger SL. Longitudinal data analysis using generalized linear models. Biometrika. 1986;73:13-22. doi:10.1093/biomet/73.1.13 https://doi.org/10.1093/biomet/73.1.13
- Gardner W, Mulvey EP, Shaw EC. Regression analyses of counts and rates: Poisson, overdispersed Poisson, and negative binomial models. Psychol Bull. 1995;118(3):392-404. doi:10.1037/0033-2909.118.3.392 https://doi.org/10.1037/0033-2909.118.3.392
Key takeaways
- Estimating a coefficient and estimating its uncertainty are separate processes: vce() chooses the variance-covariance matrix, and standard errors are the square roots of its diagonal, while its covariances are needed for any sum of coefficients.
- A standard error is not the spread of the data: with a variance of 18 across 100 hospitals, the standard error of the mean is 0.4243, and it shrinks as the sample grows.
- The robust sandwich A^-1 B A^-1 replaces the model's variance with squared residuals; for the 100 hospitals it gives 0.0849 against the model-based 0.0447, with the coefficient 1.6094 unchanged.
- A robust standard error is not always larger: for the binary risk ratio it is 0.2345 against the Poisson 0.2739, because the Bernoulli variance is below the Poisson working variance.
- vce(cluster id) adds the score contributions within each cluster before squaring; it needs independent, numerous clusters and, like vce(robust), cannot fix a wrong mean model, confounding or selection.
Related in the wiki: [[sandwich-standard-error-worked-by-hand]] [[heteroskedasticity-robust-standard-errors]] [[repeated-measures-modeling-guide]] [[poisson-regression-rates-lambda]] [[cluster-randomized-trials-design-ethics]]