I'm trying to figure out how to calculate clustered standard errors via boostrap when the clusters are nested. I know that when there is a single level of clustering, you sample at the cluster level rather than at the individual level. Any idea what you do when there are multiple nested levels?

To be more concrete, let's say I'm analyzing student performance and I have country-level data. In this context, I may want to cluster by state, city, and school.


3 Answers 3


I believe you are looking for the bootcov function in R that allows calculations of standard errors for nested clusters. This is well described in Huang 2016, you should have a look at the examples they give in the supplementary materials where they provide the full R script they used for this analysis.

Huang, Francis L. "Using cluster bootstrapping to analyze nested data with a few clusters." Educational and Psychological Measurement (2016): 0013164416678980.

Using a Monte Carlo simulation that varied the number of clusters, average cluster size, and intraclass correlations, we compared standard errors using cluster bootstrapping with those derived using ordinary least squares regression and multilevel models. Results indicate that cluster bootstrapping, though more computationally demanding, can be used as an alternative procedure for the analysis of clustered data when treatment effects at the group level are of primary interest. Supplementary material showing how to perform cluster bootstrapped regressions using R is also provided.


  • 1
    $\begingroup$ Thanks. Had a look and this is still only for the case where there is a single level of clustering. My question is for when there are multiple levels of clusters that are nested. $\endgroup$
    – Luke
    Commented Feb 19, 2018 at 17:40
  • $\begingroup$ Sorry didn't realize that, maybe you'd have more chance on the programming forum as it doesn't look like there is any package currently available. $\endgroup$
    – Nakx
    Commented Feb 19, 2018 at 22:21

The bootstrap on clusters, using the coarsest level of clusters, is valid even if there is clustering at finer levels within each cluster. That's because the bootstrap doesn't make any assumptions about the internal structure of each cluster. It assumes only that the clusters are exchangeable, so that a simple random sample of them (with replacement) is a way to generate data from the right distribution.

Assuming exchangeability, whatever the complicated internal structure of the clusters looks like, the complicated internal structure of the bootstrap resampled clusters will look just the same.

There are multilevel bootstraps used in some contexts for survey data, especially if the exchangeability assumption is problematic because of stratified sampling and finite population size. One example is given by Preston (2009) and implemented in the survey package for R. I don't think it's needed in your context, though.


Please refer to Nichols and Schaffer (2007). For nested clusters, you can use svy in Stata. However, clustering at the country level allows for the most robust variance-covariance structure. The minimum number of clusters should be around 50.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.