Specifies a hierarchical (nesting) level in the model where group-level units are nested within higher-level entities. Unlike multiple-membership structures, each group belongs to exactly one nesting-level unit. Can model either random effects or fixed effects at the nesting level.
Arguments
- id
An
idobject specifying the nesting-level identifier:id(hmid)wherehmididentifies the higher-level units (e.g., countries, regions).- vars
A
varsobject specifying nesting-level covariates, orNULLfor intercept-only effects. Supports interactions (*,:) and transformations (I()).- name
Unquoted variable name for nesting-level labels (optional). If provided, these labels will be displayed in model output for fixed effects.
- type
Character; either
"RE"for random effects (default) or"FE"for fixed effects at the nesting level.- showFE
Logical; if
TRUEandtype = "FE", fixed effect estimates for each nesting-level unit are included in output. Default:FALSE.- ar
Logical; if
TRUE, random effects evolve autoregressively across participations at the nesting level. Requires sequential participation indicators in the data. Default:FALSE.
Details
Hierarchical vs. Multiple-Membership:
Hierarchical structures (hm) model strict nesting: each group belongs to
exactly one higher-level unit. Use mm when groups can have
memberships in multiple units.
Random vs. Fixed Effects:
Random effects (
type = "RE"): Nesting-level units are treated as a random sample from a population. Best when you have many units and want to generalize.Fixed effects (
type = "FE"): Each unit gets its own parameter. Best when you have few units or want to estimate unit-specific effects.
Cross-Classification:
Multiple hm() blocks create cross-classified models where groups are
simultaneously nested within multiple non-nested hierarchies (e.g., schools
within both neighborhoods and districts).
References
Goldstein, H. (2011). Multilevel Statistical Models (4th ed.). Wiley.
Rabe-Hesketh, S., & Skrondal, A. (2012). Multilevel and Longitudinal Modeling Using Stata (3rd ed.). Stata Press.
Examples
if (FALSE) { # \dontrun{
# Random effects with covariates
hm(
id = id(cid),
vars = vars(gdp + democracy),
name = cname,
type = "RE"
)
# Random intercepts only
hm(
id = id(cid),
vars = NULL,
type = "RE"
)
# Fixed effects
hm(
id = id(cid),
vars = NULL,
name = cname,
type = "FE",
showFE = TRUE # Show estimates for each country
)
# Autoregressive random effects
hm(
id = id(cid),
vars = NULL,
type = "RE",
ar = TRUE # Effects evolve over time
)
} # }