Tabellab

Sample vs Population: Comparing the Margins (Age, Gender, Region)

Lesson 1 of 20Lab

All lessons
  1. Sample vs Population: Comparing the Margins (Age, Gender, Region)LabFree
  2. Cell Weighting: Post-Stratification on Age × RegionLab Locked
  3. Raking by Iterative Proportional Fitting (IPF): Two Margins, Four StepsLab Locked
  4. Weight Trimming & Capping: Limits, Rescaling and Who Is AffectedLab Locked
  5. Weighted Estimates with SUMPRODUCT vs Unweighted ResultsLab Locked
  6. Kish Effective Sample Size & Design Effect: Raked vs Trimmed WeightsLab Locked
  7. Weighted Margin of Error: z, √deff and SubgroupsLab Locked
  8. Before vs After Weighting: Gap Table & Comparison ChartLab Locked
  9. Base Weights: Selection Probabilities, One Adult per Household and a CapLab Locked
  10. Nonresponse Adjustment: Response Rates by Class and Adjustment FactorsLab Locked
  11. Raking to Three Margins: Age, Gender and Region on a Cell List with SUMIFSLab Locked
  12. Raking Convergence: Iteration Log, Tolerance and a Gap ChartLab Locked
  13. Sparse Cells: Minimum Cell Size and Collapsing Before WeightingLab Locked
  14. Trimming in Rounds: Trim, Rescale, Repeat Until the Limits HoldLab Locked
  15. Weight Diagnostics: Spread, CV, Top-Weight Share and a Weight HistogramLab Locked
  16. Weighted Cross-Tabs: Weighted Counts, Row Percentages and Unweighted BasesLab Locked
  17. Weighted Medians and Percentiles from Sorted Respondent RecordsLab Locked
  18. Replication Variance: Delete-a-Group Jackknife Standard ErrorsLab Locked
  19. Choosing a Weighting Scheme: Bias, Precision and Total Error Against a BenchmarkLab Locked
  20. Final Project: Weighting Report Dashboard for a New Survey WaveLab Locked

You are not signed in — the lab works, but your progress is not saved. Sign up

Lesson 1 of 20 is free. Unlock all 20 hands-on labs, the final exam and your certificate.

Buy course — €9.90
Loading the spreadsheet…

Your survey is not your population

Surveys rarely reach the people they are meant to describe in the right proportions. Retired residents answer the phone, students do not. Commuters with strong opinions click the link, people who are merely satisfied ignore it. The result is a sample that leans toward some groups and away from others, and every headline number you calculate from it inherits that lean. Survey weighting is the standard way to correct it, and the first step is always the same: compare the sample with the population and measure the gaps.

This course is for market researchers, public-sector analysts, students writing a thesis with questionnaire data, HR teams running employee surveys, and anyone who has to report "x% of customers are satisfied" from a sample. You will build every step of a weighting scheme in Excel: post-stratification, raking by iterative proportional fitting, trimming, weighted estimates, the design effect and a weighted margin of error. No statistics package is needed. This free first lesson does the groundwork that every one of those steps depends on: the margin comparison.

The lab uses the fictional Lakemoor Regional Transit Authority, which interviewed 1,200 adults about buses and trams. The region has 640,000 adults according to a (synthetic) census. Older residents and suburban commuters answered eagerly, young adults did not. All data is invented for practice.

The core concept: margins, gaps and a first-guess weight

A margin is the distribution of one variable on its own: the share of each age group, the share of women and men, the share of each region. You need the margins of the sample (from your interviews) and of the population (from a census, a register or another trusted source). Comparing them variable by variable answers three questions:

  1. Sample share = interviews in the group ÷ all interviews (n). For 18–34 year olds: 228 ÷ 1,200 = 19.0%.
  2. Population share = adults in the group ÷ all adults (N). For 18–34: 192,000 ÷ 640,000 = 30.0%.
  3. Gap = sample share − population share, in percentage points. For 18–34: 19.0% − 30.0% = −11.0 points. A negative gap means the group is missing from the sample, a positive gap means it is over-represented.

From the two shares you also get a first-guess weight: population share ÷ sample share. For 18–34 that is 30.0% ÷ 19.0% = 1.58, which means each young respondent has to speak for 1.58 "average" respondents if the age distribution is to match the population. Groups with a ratio below 1 get weighted down: each person aged 55+ counts as 0.76 of a respondent. Note that this is a relative weight that averages to 1 across the sample. Multiply it by N ÷ n (here 640,000 ÷ 1,200 ≈ 533) and you get an expansion weight, the number of adults each interview represents.

One ratio per variable is not yet a weighting scheme, because a person is young and a woman and lives in the city at the same time. Combining the margins correctly is what post-stratification and raking do later in the course. But the ratios already tell you where the work will be, and a ratio far above 1 is an early warning: it means a small, hard-to-reach group will carry a lot of weight, which increases the variance of every estimate.

Choosing the variables to compare

Which variables should you compare? Good weighting variables meet three conditions. First, reliable population figures exist for them, from a census, a register or your own customer or employee database. Second, they were asked in the survey in exactly the same categories, so that "35–54" means the same thing in both sources. Third, they are related to the topics of the survey or to the willingness to answer. Age, gender and region are the classic trio because they meet all three conditions in most countries. Education, household size or, for customer surveys, plan type and tenure are common additions.

Fewer, well-measured variables are usually better than many. Every extra variable adds categories, and categories with only a handful of interviews produce large and unstable weights. That is why the lab keeps three variables with two or three groups each. When you design your own survey, decide on the weighting variables before fieldwork, so that the questions are worded to match the population source and every respondent answers them.

Worked example: the Lakemoor transit survey

Here are all eight groups from the lab. Each variable block (age, gender, region) adds up to the same 1,200 interviews and the same 640,000 adults, which is why one n in C13 and one N in D14 are enough for every row.

Lakemoor Transit Survey 2026: 1,200 interviews vs 640,000 adults (fictional, synthetic data)
VariableGroupInterviewsAdults (census)Sample share (E)Population share (F)Gap, points (G)Pop ÷ sample (H)
Age18–34228192,00019.0%30.0%−11.01.58
Age35–54432230,40036.0%36.0%0.01.00
Age55+540217,60045.0%34.0%+11.00.76
GenderWomen708329,60059.0%51.5%+7.50.87
GenderMen492310,40041.0%48.5%−7.51.18
RegionCity456281,60038.0%44.0%−6.01.16
RegionSuburbs516230,40043.0%36.0%+7.00.84
RegionRural228128,00019.0%20.0%−1.01.05

Reading the table from top to bottom: the age margin shows the biggest imbalance, 18–34 year olds are 11 points short and people aged 55+ are 11 points over. The 35–54 group happens to match exactly, so its ratio is 1.00. Women are over-represented by 7.5 points, a pattern many survey teams see in practice. In the regions, suburbs are 7 points over and the city is 6 points short, while rural residents are almost on target. The most under-represented group, the answer to the lab's last task, is 18–34 with a ratio of 1.58.

Sample share vs population share (n = 1,200)samplepopulation18–34Age19.0%30.0%35–5436.0%36.0%55+45.0%34.0%WomenGender59.0%51.5%Men41.0%48.5%CityRegion38.0%44.0%Suburbs43.0%36.0%Rural19.0%20.0%
Sample shares (peach) and population shares (sky) for the eight groups in the lab. Within each variable the shares add up to 100%.

Gap in percentage points and first-guess weight← missing in sampleover-represented →pop ÷ sample18–34−11.01.5835–540.01.0055++11.00.76Women+7.50.87Men−7.51.18City−6.01.16Suburbs+7.00.84Rural−1.01.05−10−50+5+10percentage points (sample share − population share)
The same comparison as gaps. Bars to the left mark groups that are missing from the sample, the right-hand column shows population share ÷ sample share. 18–34 needs the largest weight, 1.58.

Why does this matter if the questions are about buses, not about age? Because opinions usually differ between groups. Suppose, for example, that 55% of 18–34 year olds, 65% of 35–54 year olds and 78% of people aged 55+ are satisfied with the service. These rates are assumed for illustration only. The unweighted result mixes them in the sample's proportions, a weighted result mixes them in the population's proportions:

Illustration with assumed satisfaction rates: what an age imbalance does to a headline number
Age groupSample sharePopulation shareSatisfied (for example)Sample × satisfiedPopulation × satisfied
18–3419.0%30.0%55%10.5%16.5%
35–5436.0%36.0%65%23.4%23.4%
55+45.0%34.0%78%35.1%26.5%
Total100.0%100.0%69.0%66.4%

The unweighted headline would say 69.0% are satisfied, the age-corrected figure is 66.4%, a difference of 2.5 points caused only by who answered. In Excel the two totals are =SUMPRODUCT(E4:E6,J4:J6) and =SUMPRODUCT(F4:F6,J4:J6) if the satisfaction rates sit in J4:J6. With real data the size and direction of the difference depend on how strongly the opinion is linked to the weighting variables, which is exactly why you check the margins first.

Step by step in Excel

These steps follow the lab above. They work in any recent Excel version, and XLOOKUP needs Excel 2021 or Microsoft 365.

  1. Check the totals. C13 holds =SUM(C4:C6) and D14 =SUM(D4:D6). Before going on, confirm that the gender rows (C7:C8) and region rows (C9:C11) also add up to 1,200, for example with =SUM(C7:C8)=C13, which should return TRUE. If a block does not add up, some respondents have a missing answer and need their own category.
  2. Sample shares. In E4 type =C4/$C$13. Type C13 and press F4 once to make it absolute. Select E4:E11 and press Ctrl+D to fill down. Rural (E11) shows 19.0%.
  3. Population shares. In F4 type =D4/$D$14 and fill down to F11. Format E4:F11 as percent with Ctrl+Shift+% and add one decimal (Home → Increase Decimal).
  4. Gaps. In G4 type =E4-F4 and fill down. The 18–34 gap is −11.0%. Excel shows a "%" sign, but read it as percentage points: the difference between two percentages.
  5. Ratios. In H4 type =F4/E4 and fill down. Rural (H11) is 1.05. Format with two decimals, not as a percentage.
  6. Find the group that needs the biggest weight. In B16 type =INDEX(B4:B11,MATCH(MAX(H4:H11),H4:H11,0)), or in Microsoft 365 =XLOOKUP(MAX(H4:H11),H4:H11,B4:B11). Both return 18–34.
  7. Make the gaps visible. Select G4:G11 and choose Home → Conditional Formatting → Data Bars. Excel draws negative bars to the left of an axis, a quick in-cell version of the gap chart above.
  8. Sanity check. =SUM(E4:E6) and =SUM(F4:F6) must both be 100%, and so must each other block. The sum of gaps within a block is always 0.
Keep population figures and their source (for example the census table name and year) on the sheet next to the numbers. Weighting targets are only as good as their source, and a reader will ask where they came from.

Common mistakes and how to spot them

Margin comparisons look trivial, but small slips here propagate into every weight you build later.

  • Ratio upside down. Sample share ÷ population share gives 0.63 for 18–34, which would weight young people further down. How to spot it: a group that is missing from the sample must get a ratio above 1.
  • Gap with the wrong sign. Population − sample flips every sign, so missing groups look over-represented. How to spot it: 18–34 must show a negative gap, since they are fewer in the sample than in the population.
  • Relative references on the totals. =C4/C13 filled down becomes =C5/C14, which divides by an empty cell and shows #DIV/0!. How to spot it: errors or 100% values from row 5 on. Use $C$13.
  • Blocks that do not add up. If some respondents did not state their age, the age block sums to less than 1,200 and the shares are off. How to spot it: check every block total against n, and add a "not stated" row instead of dropping people silently.
  • Mismatched definitions. A census that counts adults aged 18+ cannot be compared with a survey of people aged 16+, and region boundaries must be the same in both sources. How to spot it: write the definition next to each population figure and compare.
  • Treating weighting as a cure-all. Weighting corrects the variables you weight on, and helps with others only to the extent that they are related. If satisfied passengers were simply more willing to answer within every age group, weighting by age does not fix it. How to spot the risk: compare weighted results with any outside benchmark you have.

Survey weighting in Excel: comparing sample and population margins before post-stratification and raking
Every weighting scheme starts with the same comparison: how far does the sample drift from the population on age, gender and region?

Quick reference: formulas and shortcuts

Everything used in this lesson, ready to copy:

Function / toolWhat it does hereExample
SUMTotal interviews n and total adults N=SUM(C4:C6) → 1,200
Absolute reference $C$13Keeps the denominator fixed while you fill down; press F4 to toggle=C4/$C$13
ShareGroup count ÷ total=D4/$D$14 → 30.0%
GapSample share − population share=E4-F4 → −11.0 points
RatioPopulation share ÷ sample share, the first-guess weight=F4/E4 → 1.58
INDEX + MATCHName of the group with the largest ratio=INDEX(B4:B11,MATCH(MAX(H4:H11),H4:H11,0))
XLOOKUP (365/2021)Same lookup in one function=XLOOKUP(MAX(H4:H11),H4:H11,B4:B11)
SUMPRODUCTShare-weighted average of a result=SUMPRODUCT(F4:F6,J4:J6)
Data BarsVisual gap columnHome → Conditional Formatting → Data Bars
Percent formatShow shares as %Ctrl+Shift+%
Fill downCopy the top formula into the selectionCtrl+D or double-click the fill handle

Real-world uses

Margin comparisons and first-guess weights come up wherever results from a sample are reported for a whole population:

  • Customer satisfaction surveys. Compare respondents with the customer base by segment, region or plan type from your CRM. If premium customers answer twice as often, the unweighted score describes them more than your customers overall.
  • Employee engagement surveys. HR has the exact headcount per department and location, so the population margins are known. A department that answered at 30% while others answered at 80% will be under-represented in the company-wide score.
  • Public consultations and transit surveys. Agencies compare respondents with census figures on age, gender and district before publishing, much like the Lakemoor example.
  • Student and thesis research. A gap table belongs in the methods chapter: it documents how the sample differs from the population and justifies the weighting that follows.
  • Online panels and polls. Opt-in samples often have large gaps on age and education. The ratio column shows quickly whether some groups would need extreme weights, which is a warning about how much the results can be trusted.

What you will build in the rest of this course

The free lesson tells you how far the sample is from the population. The remaining 19 lessons turn that into proper weights, apply them and measure what weighting costs in precision. They are part of the paid course, a one-time purchase of $9.90, and each one is a lab on the same Lakemoor survey, so the numbers carry through from lesson to lesson.

Cell Weighting: Post-Stratification on Age × Region. You will build expansion weights and relative weights for nine age × region cells, check that the weighted sample still adds up to 1,200 interviews, and find the cells whose weights are large enough to be risky.

Raking by Iterative Proportional Fitting (IPF): Two Margins, Four Steps. When you only know the margins, not the joint table, raking is the standard answer. You will rake a 3 × 3 table to the age margin and the region margin in turn, watch the totals converge after two rounds and read off a raked weight.

Weight Trimming & Capping: Limits, Rescaling and Who Is Affected. Large weights make estimates unstable. You will cap raked weights at 0.5 and 2.5, rescale them so they add up to 1,200 again, and count how many interviews the trimming touched.

Weighted Estimates with SUMPRODUCT vs Unweighted Results. This is where weights change the answers. You will calculate weighted means and shares from respondent records with SUMPRODUCT, including a weighted share for one region, and compare them with the unweighted numbers.

Kish Effective Sample Size & Design Effect: Raked vs Trimmed Weights. Weighting has a price. You will compute Kish's effective sample size and the design effect for the raked and the trimmed weights, and see how many effective interviews trimming wins back.

Weighted Margin of Error: z, √deff and Subgroups. You will calculate the textbook margin of error, widen it with the square root of the design effect, repeat it for the small rural subgroup and report the upper end of the interval, the way a careful survey report should.

Before vs After Weighting: Gap Table & Comparison Chart. Lab 8 closes the loop: weighted shares, the absolute gap to the population before and after weighting, and a chart of population, sample and weighted shares side by side that shows the effect of the whole scheme at a glance.

Summary

Before you weight a survey, compare its margins with the population. Sample share = group ÷ n, population share = group ÷ N, gap = sample − population in percentage points, and population share ÷ sample share is the first-guess weight. In the Lakemoor survey, 18–34 year olds are 11 points short and need a weight of about 1.58, while people aged 55+ are 11 points over and get 0.76. Because opinions differ between groups, these gaps can move a headline result by several points.

Scroll up to the lab and build the comparison yourself: sample shares, population shares, gaps, ratios and the most under-represented group. The Coach checks each step, and it takes about 15 minutes.

Frequently asked questions

What is survey weighting?

Survey weighting gives each respondent a weight so that the weighted sample matches known population figures, such as the shares of age groups or regions. It corrects for groups that answered more or less often than their share of the population.

How do you calculate a survey weight in Excel?

The simplest weight for one variable is population share divided by sample share, for example =F4/E4. A group that is 30% of the population but 19% of the sample gets a weight of about 1.58.

What is the difference between post-stratification and raking?

Post-stratification weights cells of a joint table, such as age × region, to known cell totals. Raking (iterative proportional fitting) adjusts weights to several margins in turn when only the separate margins are known.

What does a negative gap between sample and population mean?

If the gap is calculated as sample share minus population share, a negative value means the group is under-represented in the sample. It will need a weight above 1.

Where do population margins for weighting come from?

Typically from a census, an official population register, or for customer and employee surveys from your own CRM or HR system. The definitions, such as age limits and region boundaries, must match the survey.

Does weighting remove all bias from a survey?

No. Weighting corrects imbalances on the variables you weight on and on characteristics related to them. If people with different opinions answer at different rates within the same group, weighting cannot fully correct it.

Keep going: Survey Weighting: Post-Stratification, Raking (IPF) & Design Effects

This free lab is lesson 1 of 20. Unlock the other 19 hands-on labs, the final exam and your certificate for a one-time €9.90.

  1. Cell Weighting: Post-Stratification on Age × Region
  2. Raking by Iterative Proportional Fitting (IPF): Two Margins, Four Steps
  3. Weight Trimming & Capping: Limits, Rescaling and Who Is Affected
  4. Weighted Estimates with SUMPRODUCT vs Unweighted Results
  5. Kish Effective Sample Size & Design Effect: Raked vs Trimmed Weights
  6. Weighted Margin of Error: z, √deff and Subgroups
  7. Before vs After Weighting: Gap Table & Comparison Chart
  8. Base Weights: Selection Probabilities, One Adult per Household and a Cap
  9. Nonresponse Adjustment: Response Rates by Class and Adjustment Factors
  10. Raking to Three Margins: Age, Gender and Region on a Cell List with SUMIFS
  11. Raking Convergence: Iteration Log, Tolerance and a Gap Chart
  12. Sparse Cells: Minimum Cell Size and Collapsing Before Weighting
  13. Trimming in Rounds: Trim, Rescale, Repeat Until the Limits Hold
  14. Weight Diagnostics: Spread, CV, Top-Weight Share and a Weight Histogram
  15. Weighted Cross-Tabs: Weighted Counts, Row Percentages and Unweighted Bases
  16. Weighted Medians and Percentiles from Sorted Respondent Records
  17. Replication Variance: Delete-a-Group Jackknife Standard Errors
  18. Choosing a Weighting Scheme: Bias, Precision and Total Error Against a Benchmark
  19. Final Project: Weighting Report Dashboard for a New Survey Wave

Buy course — €9.90 See the full course