Complex survey analysis
Start with the expanded example for each command. Open the variants for options and alternative R approaches. Read the qualifications before adapting the code.
estat
Coefficient of variation of a survey mean
Stata
estat cvR Package:survey
survey::cv(survey::svymean(~y, des))Differs from Stata Fixed workflow; adapt the named data columns explicitly. Relative standard error is unstable when the estimated mean is near zero.
1 more examples and alternatives
Design effect of a survey mean
Stata
estat effectsR Package:survey
survey::deff(survey::svymean(~y, des, deff = TRUE))Differs from Stata Fixed workflow; adapt the named data columns explicitly. Design effects depend on the SRS comparison, finite-population correction and weight scaling.
svy
Survey mean with bootstrap replicate variance
Stata
svy bootstrap: mean yR Package:survey
{ reps <- survey::as.svrepdesign(des, type = "bootstrap"); survey::svymean(~y, reps) }Differs from Stata Fixed workflow; adapt the named data columns explicitly. Point means agree with sampling weights; replication variance depends on the chosen scheme.
30 more examples and alternatives
Survey mean with BRR replicate variance
Stata
svy brr: mean yR Package:survey
{ reps <- survey::as.svrepdesign(des, type = "BRR"); survey::svymean(~y, reps) }Differs from Stata Fixed workflow; adapt the named data columns explicitly. Point means agree with sampling weights; replication variance depends on the chosen scheme.
Survey mean with JKn replicate variance
Stata
svy jackknife: mean yR Package:survey
{ reps <- survey::as.svrepdesign(des, type = "JKn"); survey::svymean(~y, reps) }Differs from Stata Fixed workflow; adapt the named data columns explicitly. Point means agree with sampling weights; replication variance depends on the chosen scheme.
Survey subpopulation mean
Stata
svy, subpop(if group==1): mean yR Package:survey
survey::svymean(~y, subset(des, group == "1"))Differs from Stata Fixed workflow; adapt the named data columns explicitly. Subset the design, preserving the sampling structure, rather than rebuilding a design after filtering.
Survey gamma log-link model
Stata
svy: glm y x, family(gamma) link(log)R Package:survey
survey::svyglm(y ~ x, des, family = stats::Gamma(link = "log"))Differs from Stata Fixed workflow; adapt the named data columns explicitly. Quasi families retain the mean/variance structure without non-integer count warnings; align design degrees of freedom.
Survey logistic regression
Stata
svy: logit yes xR Package:survey
survey::svyglm(yes ~ x, des, family = stats::quasibinomial())Differs from Stata Fixed workflow; adapt the named data columns explicitly. Quasi families retain the mean/variance structure without non-integer count warnings; align design degrees of freedom.
Survey-weighted mean
Stata
svy: mean yR Package:survey
survey::svymean(~y, des)Differs from Stata Fixed workflow; adapt the named data columns explicitly. Design-based variance uses the full sampling design; population totals require correctly scaled weights.
Joint means and covariance matrix
Stata
svy: mean y xR Package:survey
survey::svymean(~y + x, des)Differs from Stata Fixed workflow; adapt the named data columns explicitly. Design-based variance uses the full sampling design; population totals require correctly scaled weights.
Domain-specific means
Stata
svy: mean y, over(group)R Package:survey
survey::svyby(~y, ~group, des, survey::svymean)Differs from Stata Fixed workflow; adapt the named data columns explicitly. Design-based variance uses the full sampling design; population totals require correctly scaled weights.
Survey Poisson mean model
Stata
svy: poisson y xR Package:survey
survey::svyglm(y ~ x, des, family = stats::quasipoisson())Differs from Stata Fixed workflow; adapt the named data columns explicitly. Quasi families retain the mean/variance structure without non-integer count warnings; align design degrees of freedom.
Survey probit regression
Stata
svy: probit yes xR Package:survey
survey::svyglm(yes ~ x, des, family = stats::quasibinomial(link = "probit"))Differs from Stata Fixed workflow; adapt the named data columns explicitly. Quasi families retain the mean/variance structure without non-integer count warnings; align design degrees of freedom.
Survey proportion interval using asin
Stata
svy: proportion yesR Package:survey
survey::svyciprop(~yes, des, method = "asin", level = .95)Fixed workflow; adapt the named data columns explicitly. Different interval constructions are intentional alternatives; match Stata’s selected transformation.
Survey proportion interval using beta
Stata
svy: proportion yesR Package:survey
survey::svyciprop(~yes, des, method = "beta", level = .95)Fixed workflow; adapt the named data columns explicitly. Different interval constructions are intentional alternatives; match Stata’s selected transformation.
Survey proportion interval using likelihood
Stata
svy: proportion yesR Package:survey
survey::svyciprop(~yes, des, method = "likelihood", level = .95)Fixed workflow; adapt the named data columns explicitly. Different interval constructions are intentional alternatives; match Stata’s selected transformation.
Survey proportion interval using logit
Stata
svy: proportion yesR Package:survey
survey::svyciprop(~yes, des, method = "logit", level = .95)Fixed workflow; adapt the named data columns explicitly. Different interval constructions are intentional alternatives; match Stata’s selected transformation.
Survey proportion interval using mean
Stata
svy: proportion yesR Package:survey
survey::svyciprop(~yes, des, method = "mean", level = .95)Fixed workflow; adapt the named data columns explicitly. Different interval constructions are intentional alternatives; match Stata’s selected transformation.
Survey proportion interval using xlogit
Stata
svy: proportion yesR Package:survey
survey::svyciprop(~yes, des, method = "xlogit", level = .95)Fixed workflow; adapt the named data columns explicitly. Different interval constructions are intentional alternatives; match Stata’s selected transformation.
Survey-weighted category proportions
Stata
svy: proportion yesR Package:survey
survey::svymean(~factor(yes), des)Differs from Stata Fixed workflow; adapt the named data columns explicitly. Design-based variance uses the full sampling design; population totals require correctly scaled weights.
Domain-specific proportions
Stata
svy: proportion yes, over(group)R Package:survey
survey::svyby(~factor(yes), ~group, des, survey::svymean)Differs from Stata Fixed workflow; adapt the named data columns explicitly. Design-based variance uses the full sampling design; population totals require correctly scaled weights.
Survey ratio of totals
Stata
svy: ratio y/xR Package:survey
survey::svyratio(~y, ~x, des)Differs from Stata Fixed workflow; adapt the named data columns explicitly. Design-based variance uses the full sampling design; population totals require correctly scaled weights.
Survey linear regression
Stata
svy: regress y xR Package:survey
survey::svyglm(y ~ x, des, family = stats::gaussian())Differs from Stata Fixed workflow; adapt the named data columns explicitly. Quasi families retain the mean/variance structure without non-integer count warnings; align design degrees of freedom.
Weighted contingency-table counts
Stata
svy: tabulate group yesR Package:survey
prop.table(survey::svytable(~group + yes, des))Differs from Stata Returns weighted cell proportions, the default display of svy: tabulate twoway. This table alone does not provide Stata design-based standard errors, confidence intervals or adjusted association tests.
Survey column proportions
Stata
svy: tabulate group yes, columnR Package:survey
prop.table(survey::svytable(~group + yes, des), margin = 2)Differs from Stata Fixed workflow; adapt the named data columns explicitly. Design-based variance uses the full sampling design; population totals require correctly scaled weights.
Design-based categorical association: Chisq
Stata
svy: tabulate group yes, pearsonR Package:survey
survey::svychisq(~group + yes, des, statistic = "Chisq")Fixed workflow; adapt the named data columns explicitly. Rao-Scott and Wald choices have distinct reference distributions; choose the intended test explicitly.
Design-based categorical association: F
Stata
svy: tabulate group yes, pearsonR Package:survey
survey::svychisq(~group + yes, des, statistic = "F")Fixed workflow; adapt the named data columns explicitly. Rao-Scott and Wald choices have distinct reference distributions; choose the intended test explicitly.
Design-based categorical association: Wald
Stata
svy: tabulate group yes, pearsonR Package:survey
survey::svychisq(~group + yes, des, statistic = "Wald")Fixed workflow; adapt the named data columns explicitly. Rao-Scott and Wald choices have distinct reference distributions; choose the intended test explicitly.
Design-based categorical association: adjWald
Stata
svy: tabulate group yes, pearsonR Package:survey
survey::svychisq(~group + yes, des, statistic = "adjWald")Fixed workflow; adapt the named data columns explicitly. Rao-Scott and Wald choices have distinct reference distributions; choose the intended test explicitly.
Survey row proportions
Stata
svy: tabulate group yes, rowR Package:survey
prop.table(survey::svytable(~group + yes, des), margin = 1)Differs from Stata Fixed workflow; adapt the named data columns explicitly. Design-based variance uses the full sampling design; population totals require correctly scaled weights.
Survey-weighted population total
Stata
svy: total yR Package:survey
survey::svytotal(~y, des)Differs from Stata Fixed workflow; adapt the named data columns explicitly. Design-based variance uses the full sampling design; population totals require correctly scaled weights.
Joint population totals
Stata
svy: total y xR Package:survey
survey::svytotal(~y + x, des)Differs from Stata Fixed workflow; adapt the named data columns explicitly. Design-based variance uses the full sampling design; population totals require correctly scaled weights.
Domain-specific population totals
Stata
svy: total y, over(group)R Package:survey
survey::svyby(~y, ~group, des, survey::svytotal)Differs from Stata Fixed workflow; adapt the named data columns explicitly. Design-based variance uses the full sampling design; population totals require correctly scaled weights.
svydescribe
Survey design degrees of freedom and cluster counts
Stata
svydescribeR Package:survey
list(degrees_of_freedom = survey::degf(des), strata = table(des$strata[, 1]), clusters = length(unique(des$cluster[, 1])))Differs from Stata Fixed workflow; adapt the named data columns explicitly. Counts observed records by stratum; PSU count is distinct from observation count.
svyset
Independent unequal-probability sample
Stata
svyset [pw=w]R Package:survey
survey::svydesign(ids = ~1, weights = ~w, data = data)Differs from Stata Fixed workflow; adapt the named data columns explicitly. Survey objects carry design metadata; do not substitute ordinary regression weights.
8 more examples and alternatives
Stratified cluster survey design
Stata
svyset psu [pw=w], strata(stratum)R Package:survey
survey::svydesign(ids = ~psu, strata = ~stratum, weights = ~w, data = data)Differs from Stata Fixed workflow; adapt the named data columns explicitly. Survey objects carry design metadata; do not substitute ordinary regression weights.
Finite-population correction in a clustered design
Stata
svyset psu [pw=w], strata(stratum) fpc(N)R Package:survey
survey::svydesign(ids = ~psu, strata = ~stratum, weights = ~w, fpc = ~N, data = data)Differs from Stata Fixed workflow; adapt the named data columns explicitly. Survey objects carry design metadata; do not substitute ordinary regression weights.
Poststratify survey weights to population category totals
Stata
svyset psu [pw=w], strata(stratum) poststrata(group) postweight(pop)R Package:survey
survey::postStratify(des, ~group, population = population)Differs from Stata Fixed workflow; adapt the named data columns explicitly. Population categories must cover the sample; weighting adjustments are part of the variance design.
Rake sample weights to known category margins
Stata
svyset psu [pw=w], strata(stratum) rake(ibn.group, totals(20 30, copy) noconstant)R Package:survey
survey::rake(des, sample.margins = list(~group), population.margins = list(population))Fixed workflow; adapt the named data columns explicitly. Survey calibration workflow; Stata’s exact calibration syntax depends on svyset options/version.
Survey bootstrap replicate-weight design
Stata
svyset psu [pw=w], strata(stratum) vce(bootstrap)R Package:survey
survey::as.svrepdesign(des, type = "bootstrap", replicates = 50)Fixed workflow; adapt the named data columns explicitly. Illustrative replication count; specific survey bootstrap schemes and scales can differ.
Balanced repeated replication for paired-PSU strata
Stata
svyset psu [pw=w], strata(stratum) vce(brr)R Package:survey
survey::as.svrepdesign(des, type = "BRR")Differs from Stata Fixed workflow; adapt the named data columns explicitly. BRR requires exactly two PSUs per stratum unless a deliberate design adjustment is made.
Fay balanced repeated replication
Stata
svyset psu [pw=w], strata(stratum) vce(brr) fay(.3)R Package:survey
survey::as.svrepdesign(des, type = "Fay", fay.rho = .3)Differs from Stata Fixed workflow; adapt the named data columns explicitly. Match Fay’s perturbation parameter and replicate scaling conventions.
Stratified delete-one jackknife replicates
Stata
svyset psu [pw=w], vce(jackknife)R Package:survey
survey::as.svrepdesign(des, type = "JKn")Differs from Stata Fixed workflow; adapt the named data columns explicitly. Survey objects carry design metadata; do not substitute ordinary regression weights.