svy: ratio
The ratio of one population total to another.
What we have
- a ratio of two estimated totals, with its standard error
Coming later
Nothing known to be missing.
How you write it
svy: mean | total | proportion | ratio | regress | tabulate ...
Square brackets mean optional. A vertical bar means choose one.
What it does
svy: ratio mpce/hhsize estimates total spending divided by total people — which is not the same thing as the average of the household ratios, and is usually the quantity you actually want.
Both parts are estimated, so the standard error accounts for the uncertainty in each and for how they move together.
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.
. svy: mean mpce, over(sector)
Survey: Mean estimation
Number of strata = 12 Number of PSUs = 400
Number of obs = 6,000
Design df = 388
| Mean Std. err. [95% conf. interval]
-----------------+--------------------------------------------------------
Rural | 3394.003 21.863 3351.018 3436.987
Urban | 4339.799 35.40776 4270.184 4409.414
The same thing in pandas and in R
pandas
# mean of ['mpce'] with linearised standard errors
R
library(survey) svyby(~mpce, ~sector, design, svymean) # This R was run in a real R (4.6.1) and gave the same numbers.
. svy: total hhsize
Survey: Total estimation
Number of strata = 12 Number of PSUs = 400
Number of obs = 6,000
Design df = 388
| Total Std. err. [95% conf. interval]
-----------------+--------------------------------------------------------
hhsize | 4.80755e+07 713048.5 4.66736e+07 4.94774e+07
The same thing in pandas and in R
pandas
# total of ['hhsize'] with linearised standard errors
R
library(survey) svytotal(~hhsize, design, na.rm = TRUE) # This R was run in a real R (4.6.1) and gave the same numbers.
. svy: proportion sector
Survey: Proportion estimation
Number of strata = 12 Number of PSUs = 400
Number of obs = 6,000
Design df = 388
| Proportion Std. err. [95% conf. interval]
-----------------+--------------------------------------------------------
sector=Rural | .7302614 .005520317 .7194079 .7411149
sector=Urban | .2697386 .005520317 .2588851 .2805921
The same thing in pandas and in R
pandas
# proportion of ['sector'] with linearised standard errors
R
library(survey) svymean(~factor(sector), design, na.rm = TRUE) # This R was run in a real R (4.6.1) and gave the same numbers.
. svy: ratio mpce/hhsize
Survey: Ratio estimation
Number of obs = 6,000
Design df = 388
| Ratio Std. err. [95% conf. interval]
-----------------+--------------------------------------------------------
mpce/hhsize | 805.5617 6.908603 791.9787 819.1447
The same thing in pandas and in R
R
# no R form for this one: a ratio needs a numerator and a denominator
Nearby
svyset svy: mean svy: total svy: proportion svy: regress svy: tabulate