Converter tool

Survey Weighting by Raking

Rake respondent weights to population margins on several variables, cap extreme weights, read the design effect and preview weighted crosstabs.

One row per respondent

1. Your data

Or paste the table

Survey Weighting by Raking

Operator: Abdulla Al Fahad. How tools are built and checked

When a sample has far more men than the population does, every unweighted percentage tilts towards what men said. Weighting repairs that by giving each respondent a number that says how many people in the population they stand for. With one variable this is a simple ratio; with age, sex and region at once, and only their totals known, it takes raking.

Raking, also called iterative proportional fitting, adjusts the weights to match the first variable's population shares, then the second's, then the third's, and repeats until all the shares hold together. You give the page a respondent file and the target shares for up to eight variables.

It returns a weight for every respondent, shows how closely each margin was met, and reports what the weights cost: the design effect and the effective sample size. A weighted crosstab lets you compare any two questions with and without the weights.

Key features

  • Raking to 1 to 8 variables with up to 60 categories each, for up to 200,000 respondents
  • Targets entered as percentages or population counts, typed per category or pasted as variable,category,value lines
  • Optional starting weights (design weights), and a cap and floor expressed as multiples of the mean weight
  • Convergence report, margin table (sample, target and weighted share for each category), weight histogram, Kish design effect and effective sample size
  • Weighted and unweighted row percentages for any two columns, and CSV exports of the data with a weight column and of the margins report
  • Respondents with a blank answer in a weighting variable are set aside and counted instead of being guessed

Targets, convergence, weight caps and how the design effect is calculated

Each row of the file is one respondent and each weighting variable is a column of categories. Any column with 2 to 60 distinct values can be used. A blank answer in a weighting variable leaves that respondent out of the raking, and the weight cell for them in the export is empty; the page counts them. Target shares are matched on the exact text of the category, after trimming spaces.

Percent targets must add to 100 within half a point; if they do not add exactly they are rescaled, and the rescaling is reported. Counts are converted to shares. A category with a target above 0 and no respondents makes the problem unsolvable, so the run stops and names that category; a category that has respondents but a target of 0 is refused the same way.

How it works

Each pass takes the variables in turn. For a variable, every category's weights are multiplied by the ratio of its target share to its current weighted share, so that variable's margin is met exactly and the others are disturbed. The pass repeats until the largest gap between any weighted share and its target is within the tolerance, 0.0001 by default (0.01 percentage points), or the iteration limit is reached; non-convergence is reported with the remaining gap. The simulated survey settles in 2 passes because its three variables were generated independently of each other, so fixing one margin barely disturbs the others; correlated variables, such as age and region in a real sample, need more passes.

With a cap or floor, each pass ends by clipping weights that are above the cap or below the floor. A cap tightens the weights but can make some targets unreachable, which is why the page reports the final gap. The reported weights are rescaled to add up to the starting total, so their mean is 1 when no starting weight was given.

Common use cases

  • A market researcher whose online panel has 62% women weights to census age, sex and region before reporting brand awareness.
  • A policy analyst checks how much a weighting scheme costs: 4,000 respondents with a design effect of 1.6 behave like 2,500.
  • A student replicates a textbook raking exercise with a 3 by 3 table and compares the fitted cell totals with the book's.

How to use this tool

  1. Drop the respondent file, paste it, or load the simulated survey.
  2. Tick the variables to weight on; the target boxes start at the sample's own shares.
  3. Type the population targets, or paste variable,category,value lines.
  4. Optionally set a cap, a floor, the tolerance and the iteration limit, then compute the weights.
  5. Check the margin table and the design effect, compare columns in the crosstab, and download the CSV with the weights.

Example

First respondent of the simulated 400-person survey, and the targets it loads

id,age_group,sex,region,satisfied
1,35-54,Male,Central,Yes
(399 more rows)
Targets: age_group 18-34 30, 35-54 35, 55+ 35; sex Male 49, Female 51; region North 25, Central 45, South 30

Weighting all 400 respondents

Sample shares before weighting: age 18-34 49.0%, sex Male 61.0%, region North 23.3%
Converged in 2 iterations; every weighted margin is within 0.01 percentage points of its target
Weights run from 0.429 to 2.678; design effect 1.291; effective sample size 309.7 of 400 (77.4%)
Overall share answering Yes: 57.8% unweighted, 63.1% weighted
With a cap of 2 times the mean: 29 respondents sit at the cap, 14 iterations, design effect 1.286

Common pitfalls

Raking matches margins, not the joint distribution. If young men are missing entirely from the sample, raking to age and sex margins cannot create them; it only gives the young men you have more weight.

A very sparse category forces very large weights. When a cell has a handful of respondents and a large target, collapse it into a neighbouring category instead of capping.

Weights change point estimates, but standard errors from the design effect are approximate, and the page does not compute weighted standard errors or confidence intervals.

  • Weight on the variables that drive both who answers and what they answer. Weighting on a variable unrelated to the outcome costs effective sample size and changes nothing.
  • Look at the weight histogram before reporting: a few respondents with weights above 4 or 5 can dominate a small subgroup, and a cap trades a little bias for much less variance.

Common errors and how to fix them

age_group: nobody in the sample is in "65+", but its target is 12.0%.
Collapse "65+" into the nearest category present in the sample, or remove it and rescale the other targets.
The percentages add up to 96.50, not 100.
Correct the targets so they add to 100 within half a point, or switch to population counts.
No respondent has an answer for every weighting variable.
A weighting column may be mis-picked or empty. Choose columns that contain answers.

Best practices

  • Collapse sparse categories before you rake: merge a 65-plus group with a handful of respondents into 55-plus rather than relying on a cap to tame its weights.
  • Rake to the margins you can source (census age, sex, region) and keep the list short; each extra variable costs effective sample size.
  • Report the design effect and the cap with every weighted figure, so a reader can judge how much the weights moved the result.

Properties you can check by hand

Raking has properties that make it easy to test. Starting from equal weights on a table whose variables are already independent, it gives each cell exactly the product of the margins: 100 respondents split 14, 56, 6 and 24 for targets of 70/30 and 20/80. It also preserves the odds ratios of the starting table, as Mosteller (1968) showed; a 3 by 3 table with unequal cells keeps its odds ratios of 1.1111 and 2.5 to 12 digits after raking.

The design effect is Kish's: n times the sum of squared weights over the square of their sum. Weights of 1, 1 and 2 give 18/16 = 1.125.

Frequently asked questions

Why did the example converge in two iterations?

Its age, sex and region columns were generated independently, so matching one margin hardly disturbs the others and the second pass is already inside the tolerance. A real file in which, say, older respondents cluster in one region has correlated variables and normally needs more passes; if it hits the iteration limit the page reports the remaining gap instead of presenting the weights as final.

What does a design effect of 1.29 mean?

The weighted estimate has about 1.29 times the variance of an unweighted sample of the same size, equivalent to 400/1.29 = 310 respondents. It is the price of the weights, from Kish's approximation, and ignores correlation between the weights and the outcome.

Should I cap the weights?

Capping at 4 or 5 times the mean is common when a few respondents get extreme weights. The page shows how many respondents sit at the cap and whether the margins still hold.

Can I cross-tabulate two questions with the weights applied?

Yes, in step 4: pick a row and a column variable and the page shows row percentages weighted and unweighted side by side. It is meant for checking how much the weights move an answer; the separate survey crosstab page on this site does plain tabulation.