← Settings in DataLion

Weighting in DataLion

Prefer to watch? The 2-minute tutorial

Playing the video sends data to YouTube (Google). Privacy policy

In DataLion you can define one or more weight variables. In the frontend, you can choose for each chart whether and with which weight the data should be weighted (gear icon → Weights).

Weight to the census

Since DataLion 2026.2.198 you can weight a sample to the adult population of one of 34 countries without your own weight variable. You map respondent ID, age and gender, and DataLion calculates the weights from the United Nations population estimates for 2023. The result shows raw, weighted and effective n plus the efficiency. The guide is Weight to the census.

Rim weighting

Since DataLion 2026.3.200 you can weight to target shares on any variables, for example age group, gender, region and education at once. DataLion adjusts the weights one variable at a time (raking) until every weighted distribution matches its targets. You only enter the target shares per variable. Unlike cell weighting, not every combination of the variables has to be present in the sample.

Rim weighting panel with the age group variable q8: four age groups with their share in the sample and the target share entered, sum 100%, followed by the Last result box with raw n 280 and effective n 269

  1. Under Admin → Projects, open the project and go to Weights in the project settings. In the Rim weighting box, click Set up rim weighting.
  2. Under Unique respondent ID, choose the ID column.
  3. Under Margins, choose the first Variable. The table lists every Value with its share in the Sample.
  4. Enter the target share for each value under Target %. The targets of a variable must add up to 100%, and the Sum row shows where you stand. If you leave a value blank, DataLion excludes its responses from the weighted results.
  5. Use Add variable to add more variables, up to ten.
  6. Click Apply rim weights. DataLion saves the weights and activates them for the project.

The weights average 1 and are trimmed to the range 0.05 to 20. The panel repeats this under Method and population targets.

Check the result

Under Last result, DataLion shows what the weighting did:

  • Converged or Not converged: whether DataLion met every target within the weight limits. If you see Not converged, check for targets that contradict each other or for sparse categories.
  • Raw n, Weighted n and Effective n. Kish’s effective n is the number of unweighted responses that would be just as precise. Efficiency is the effective n divided by the included cases.
  • Included, Excluded and the Weight range from the smallest to the largest weight.
  • Under Weighting diagnostics: the Design effect (Kish), the Weight variation (CV), the number of Iterations and the Largest target gap: before → after in percentage points. A design effect of 1 means the weighting costs no precision.
  • Fit per variable shows the same gap for each variable on its own.
  • Targets without responses lists target values that no included response has. Those shares can’t be reached.

Last result of a rim weighting on 280 cases: converged, efficiency 95.9%, effective n 269, design effect 1.04, one iteration and the largest gap for q8 falling from 6.79 to 0 percentage points

A gap close to zero shows the targets were met. On its own, that doesn’t make the sample representative.

Effective sample size in charts and significance tests

Since DataLion 2026.3.200, weighted charts and tables show Kish’s effective sample size next to the base, for example “n=4,000 cases, n eff.=3,884”. The footers of Excel and PowerPoint exports carry the same figure. The more uneven the weights, the smaller it gets.

Z-tests and chi-square tests on weighted shares use the effective sample size as their base. As a result they flag fewer differences that only look significant because of the weighting. The chart legend says so. More on the tests in Show significances in tables and charts.

Weights in the project settings

The settings for weights are under Admin → Projects, in the project under Weights. Weights can be used directly from the uploaded dataset (A) or pulled in from a separate weights table (B). Advanced option: if needed, weights can be calculated within DataLion (C).

image-20240916-074801.png

A - Using weights in a DataLion project

(1) Weights: Enter the weighting variable (the name of the variable in the dataset). For multiple weighting variables, enter them comma-separated (caution! separate without spaces).
It is also possible to use formulas to calculate the weights (example: Weight1*2*Variable | multiplies the weighting variable Weight1 by 2 and by another variable).

(2) Weight legend: Enter how the variable(s) should be labeled for users in the frontend (example: [“Weight1”,“Weight2-id”,“Weight2-id&month”])

(3) Weights to base: Optionally enter a base against which the weights should be calculated.

(9) Weight selection: Specify whether the weighting variables should be visible to users in the frontend

B - Using a weighting variable from a separate table

In DataLion, weights can also be used from a separate table. This weighting table can be uploaded into the project as its own data source (project backend > Data Sources). The software can access the weighting via joins. The following information is required for this:

(4) Separate weights table: ‘Yes’ to use weights from a separate table

(5) Weights table keys: Name of the key variable for linking the weighting table to the dataset, typically a unique ID.

  • Match via one variable: Enter the variable name (example: id | matching is done via the variable id)

  • Match via multiple variables: Enter the variable names comma-separated (without spaces!) (example: id,month | matching is done via the variables id AND month)

  • If you want to define multiple weights and these should be matched via different variables, separate the different variables (combinations) with a ”:” (example: id:id,month | the first weight variable is matched via the variable id; the second weight variable is matched via the variables id AND month)

(6) Weights table suffix: Suffix that was assigned to the weighting table during data import via the “Data Sources” tab.

C - Have weights calculated from a separate table [advanced]

When using a weighting table, weights can optionally also be calculated by DataLion on the basis of a script.

Procedure:

  1. Step: In the field (7) Weights script configuration, enter the code for the calculation (see example below)

  2. Step: Click (8) Update weights

  3. Step: Click save

The code in the Weights script configuration input field generates weights so that cells have the same distribution as in the target specification.

Up to release 2026.2.199, DataLion inverted the cell factors of these scripts. This is fixed in 2026.3.200. Affected projects get correct weights on their next recalculation, for example via (8) Update weights. If you need to weight on several variables at once, rim weighting is usually the simpler route.

Example: The code below creates weights so that the distribution of the two categories “0” and “1” of the variable “Q1” is 60% to 40%:

{“label”: “Update weights”, “type”: “cell”, “targets”: {“Q1”: {“0”: 0.6, “1”: 0.4}}, “weight_column”: “weight”, “id_column”: “id”}

  1. Weighting script parameters:

“label”: “Update weights"
"type”: “Cell”: Calculates the weights on the basis of the cells
”targets”: Target variable on the basis of which the weights should be calculated, and the weighting specification in this format: {“Variable”: {“Category1”: proportion, “Category2”: proportion}}
“weight_column”: Name of the weighting variable in the weighting table
”id_column”: Column in the dataset that contains a unique ID. Normally this is the key variable that links the weighting table to the data table.