Survey sampling with Mexican public data

Designing a quick count on the 2021 INE election results · Estimating housing need from the ENVI 2020 survey

Author

Aaron Mauricio Gómez Jiménez

2022 (original team project) · revised November 2026

Based on a 2022 class project with Daniel Franco Zárraga and Jorge Sandoval Mendoza (Survey Sampling, Facultad de Ciencias, UNAM); re-implemented and extended in 2026. The original documents are in the repository.

Population
163,666
polling stations, 2021 federal deputies (INE)
Margin of error, 900 stations
±0.87 vs ±3.9
percentage points: stratified by district vs two-stage clusters
Design effect
0.52 vs 10.3
same sample size, 3 designs × 5,000 simulated samples
ENVI 2020
33 / 33
estimates match INEGI’s official tables exactly

Summary

Two problems that a statistics office solves every day:

  1. Designing a sample. If a new federal election were held, how should 900 polling stations be chosen to estimate the vote share of the Morena–PT–PVEM coalition as precisely as possible? Using the full 2021 results as the population, I compare three designs exactly (variance formulas) and by simulation (5,000 samples each).
  2. Analysing a complex survey. How many Mexican households need to rent, buy or build a home? I estimate it from the ENVI 2020 microdata, using INEGI’s stratified two-stage design, and reproduce the official figures exactly.

The headline: with the same 900 polling stations, a sample stratified by district estimates the coalition’s national vote share within ±0.87 percentage points, while a sample concentrated in 30 districts gets only ±3.9 points. Same sample size, a variance about 20 times larger: the design, not the number of stations, decides the precision.

The first 100 of 5,000 simulated quick counts per design. Each line is one sample’s estimate and 95% confidence interval; red intervals miss the true share.

What this shows

  • Design-based inference: Horvitz–Thompson weights, the ratio estimator and its variance by Taylor linearisation, written from scratch and checked by simulation.
  • Why design choices matter: with the same 900 stations, stratifying by district halves the variance of simple random sampling, while sampling few districts multiplies it by ten.
  • Working with real survey microdata: strata, primary sampling units and expansion factors with the survey package, validated number by number against INEGI’s published tables.

Part 1. Designing a quick count

The population and the parameter

The population is every polling station (casilla) in the 2021 election for federal deputies: 163,666 stations in 300 districts, grouped in 5 electoral circumscriptions. For each station \(k\):

  • \(y_k\) = votes for the coalition (Morena, PT, PVEM, or any of their joint combinations on the ballot);
  • \(z_k\) = valid votes (total votes minus null votes).

The parameter is the coalition’s share of valid votes, a ratio of two population totals:

\[ R = \frac{t_y}{t_z} = \frac{\sum_{k \in U} y_k}{\sum_{k \in U} z_k} = 44.285\%. \]

Three designs with 900 stations each

Design How the 900 stations are chosen Inclusion probability \(\pi_k\)
I. Simple random sample 900 stations at random from the whole country \(n/N\)
II. Stratified by district 3 stations at random in each of the 300 districts \(3/N_h\) in district \(h\)
III. Two-stage by circumscription In each of the 5 circumscriptions, 6 districts at random; in each selected district, 30 stations at random \(\dfrac{6}{M_c} \cdot \dfrac{30}{N_i}\)

Estimator and variance

Both totals are estimated with Horvitz–Thompson weights \(w_k = 1/\pi_k\), and the share with the ratio estimator:

\[ \hat R = \frac{\hat t_y}{\hat t_z} = \frac{\sum_{k \in s} w_k\, y_k}{\sum_{k \in s} w_k\, z_k}. \]

The denominator is random too (the number of valid votes in the sample varies), so \(\hat R\) is not linear. A first-order Taylor expansion makes it linear:

\[ \hat R - R \approx \sum_{k \in s} w_k\, u_k, \qquad u_k = \frac{y_k - R\, z_k}{t_z}, \]

so the variance of \(\hat R\) is the variance of the Horvitz–Thompson estimator of the total of \(u\). For each design this has a closed form:

\[ \begin{aligned} V_{\text{I}} &= N^2\Big(1-\tfrac{n}{N}\Big)\frac{S_u^2}{n}, \qquad V_{\text{II}} = \sum_{h=1}^{300} N_h^2\Big(1-\tfrac{n_h}{N_h}\Big)\frac{S_{u,h}^2}{n_h}, \\ V_{\text{III}} &= \sum_{c=1}^{5}\left[ M_c^2\Big(1-\tfrac{m_c}{M_c}\Big)\frac{S_{T,c}^2}{m_c} + \frac{M_c}{m_c}\sum_{i \in c} N_i^2\Big(1-\tfrac{n_i}{N_i}\Big)\frac{S_{u,i}^2}{n_i} \right], \end{aligned} \]

where \(S_{T,c}^2\) is the variance of the district totals \(T_i = \sum_{k \in i} u_k\) within circumscription \(c\): the between-district component. In each simulated sample, the same formulas with sample variances (and \(\hat R\) in place of \(R\)) give an estimated variance and a 95% confidence interval.

Results

5,000 samples per design. True share: 44.285%. pp = percentage points.
Design Mean of estimates (%) Bias (pp) SE: theory (pp) SE: simulation (pp) 95% CI coverage Design effect Effective n
I. Simple random sample (900 stations) 44.28 -0.005 0.612 0.619 94.5% 1.00 900
II. Stratified by district (300 × 3) 44.28 -0.007 0.442 0.444 94.8% 0.52 1,723
III. Two-stage by circumscription (5 × 6 districts × 30) 44.28 -0.001 1.969 1.957 93.7% 10.35 87

Distribution of the estimated share over 5,000 samples of each design.
  • All three designs are essentially unbiased (bias below 0.01 percentage points). The ratio estimator’s bias is of order \(1/n\) and negligible here.
  • Theory and simulation agree: the linearised variance matches the spread of the 5,000 estimates, and the variance estimated from a single sample gives confidence intervals with close to nominal coverage.
  • Precision is what differs, by a factor of more than four in standard error.

Standard errors from the closed-form variance, from the simulation and estimated from each sample.

Why the designs differ

The coalition’s share varies a lot between districts and much less within a district. That single fact explains the results:

  • Stratifying by district removes the between-district variation from the error: every district is in the sample, so only within-district variation remains. The design effect is 0.52: 900 stratified stations are worth about 1,723 stations sampled at random.
  • Sampling only 30 districts (design III) puts the between-district variation back, and amplifies it: 30 stations from the same district are similar to each other (positive intraclass correlation), so they add little new information. The design effect is 10.3: the 900 stations are worth about 87.

Cluster sampling is still used in practice because visiting a few areas is cheaper. The question is how to split the sample between the two stages. The 2022 report suggested sampling more districts and fewer stations per district; the variance formula confirms it:

Design effect of the two-stage design for different splits of the same 900 stations. At 60 × 3 almost every district is in the sample and the design approaches design II.
Two-stage design with 900 stations: exact standard error and design effect by allocation.
Districts per circumscription Stations per district SE (pp) Design effect
6 30 1.97 10.35
10 18 1.50 5.98
15 12 1.19 3.80
30 6 0.78 1.62
45 4 0.58 0.89
60 3 0.44 0.53

With 30 districts × 6 stations per circumscription the design effect falls from 10.3 to 1.6.

Part 2. Housing need from the ENVI 2020 survey

The survey design

The Encuesta Nacional de Vivienda (ENVI) 2020 interviewed 56,578 households. Its design is probabilistic, two-stage, stratified and clustered: 552 design strata (EST_DIS), 8,278 primary sampling units (UPM_DIS) and an expansion factor for each household (FACTOR). Ignoring this structure and treating the households as a simple random sample would give wrong standard errors.

The question analysed is P3A1.1: Does anyone in this household need, or plan, to rent, buy or build a home, apart from the one they live in now?

library(survey)
des <- svydesign(ids = ~UPM_DIS, strata = ~EST_DIS, weights = ~FACTOR,
                 data = envi, nest = TRUE)
svytotal(~need, des)                                  # number of households
svymean(~need, des, deff = TRUE)                      # share and design effect
svyby(~need, ~ENT, des, svymean)                      # by state

National estimate

7,628,562 households had a housing need in 2020 (90% CI 7,454,281 to 7,802,843), 21.1% of the 36,210,467 households in the country (90% CI 20.6% to 21.5%). The design effect of the national share is 2.26: the clustered design is about half as efficient as a simple random sample of the same size, a typical value for household surveys.

Validation against INEGI’s official tables

INEGI publishes this indicator in the ENVI 2020 basic tabulations (Cuadro 5.1), with standard errors and 90% intervals. My estimates reproduce them exactly for the country and all 32 states:

Selected rows. Across all 33 rows, the largest difference is 0 households in the totals and 4.7e-11 percentage points in the shares; the ratio of standard errors of the shares is 1.000–1.000. Full comparison in results/envi_check_vs_inegi.csv.
Area Households with need (this analysis) INEGI % (this analysis) % INEGI SE of % (this analysis) SE INEGI
Mexico (national) 7,628,562 7,628,562 21.07 21.07 0.258 0.258
Ciudad de México 759,121 759,121 27.03 27.03 1.223 1.223
Guerrero 303,266 303,266 31.28 31.28 1.438 1.438
Nuevo León 197,403 197,403 11.59 11.59 1.014 1.014

Results by state

Share of households with a housing need, by state, with 90% confidence intervals. The shaded band is the national 90% interval.

The same estimates on a tile map of Mexico.

Housing need ranges from 11.6% in Nuevo León to 31.3% in Guerrero, and their intervals do not overlap with the national one. All 33 estimates have a coefficient of variation below 15%, INEGI’s threshold for high precision (largest: 8.7%).

About this project

2022 (team): class project for Survey Sampling (semester 2022-2, Facultad de Ciencias, UNAM; instructor Dr. Gonzalo Pérez de la Cruz), by Daniel Franco Zárraga, Aaron Mauricio Gómez Jiménez and Jorge Sandoval Mendoza. Original documents.

2026 (Aaron Mauricio Gómez Jiménez): re-implemented from scratch and extended:

  • reproducible download of the official INE and INEGI data;
  • closed-form linearised variances for the three designs, variance estimators and confidence-interval coverage, checked against 5,000 simulated samples per design;
  • the allocation analysis for the two-stage design;
  • the ENVI 2020 analysis with the survey package, validated against INEGI’s published estimates and standard errors.

Reproduce it

Rscript run_all.R   # downloads ~40 MB of public data on the first run; about a minute after that

Data: INE, Cómputos Distritales 2021, federal deputies (computos2021.ine.mx); INEGI, Encuesta Nacional de Vivienda (ENVI) 2020, open data and basic tabulations (inegi.org.mx).