Virata manual

svyset

Tells Virata how the sample was drawn, once, before any survey command.

What we have

  • one stage: the sampling unit, strata() and [pw=]
  • singleunit(), for a stratum with one unit in it

Coming later

  • several stages of sampling
  • finite population corrections (fpc())
  • replicate weights — bootstrap, jackknife and BRR

How you write it

svyset psu [pw=weight], strata(stratum) [singleunit(certainty)]

Square brackets mean optional. A vertical bar means choose one.

What it does

Real surveys are not simple random samples. They pick villages first and households inside them (clusters, or primary sampling units), they split the country into groups and sample within each (strata), and they give each household a weight saying how many households it stands for.

svyset village [pw=multiplier], strata(stratum) records all three. Every svy: command afterwards uses it. You do this once per dataset.

Why it matters: households in the same village resemble each other, so a sample of 6,000 spread over 400 villages carries less information than 6,000 independent households. Ignore that and every confidence interval you print is too narrow, and results look more certain than they are.

Watch out. The weights live on the design, not on the command. Once you have run svyset, a [pw=...] on an individual svy: command is refused.

Try it

Every example below was run after sysuse vira.sample02, clear.

. svyset village [pw=multiplier], strata(stratum)
      pweight: multiplier
          VCE: linearized
  Single unit: missing
     Strata 1: stratum
 Sampling unit 1: village
        FPC 1: <zero>
The same thing in pandas and in R

pandas

design = dict(psu='village', strata='stratum', weight='multiplier')

R

library(survey)
design <- svydesign(ids = ~village, strata = ~stratum,
    weights = ~multiplier, data = df, nest = TRUE)

# This R was run in a real R (4.6.1) and gave the same numbers.

Nearby

svy: mean svy: total svy: proportion svy: ratio svy: regress svy: tabulate