Formulas for calculating respondent weightings


Formulas can be used when calculating respondent weightings.

Continuous respondent weightings using formulas

When calculating weightings, formulas can be used to describe a continuous weighting scale based on respondents’ information.

For example, if you want to weight respondents by age, you can retrieve the age information from a question, then multiply it by a scaling factor.

Retrieve responses from answers using the answer(question_id, [item_id], [stimulus_id]) function. We can obtain the id navigating to the Additional questions and selecting View as JSON. The question id will be in the id field.

If you wanted respondents to be weighted based on whether their age is above 50 (weight of 1), exactly 50 (weight of 0.5), or below 50 (weight 0.1), the formula will be:

ifs(answer(1559304)>50,1,answer(1559304)==50,0.5,0.1,0)

or, almost equivalently:

(answer(1559304)>50) + (answer(1559304)==50)*0.5 + (answer(1559304)<50 & answer(1559304)>0)*0.1

Post-processing rules for respondent weightings

  • Boolean values are converted to 0 or 1.
  • Text values are converted into numbers, and if impossible, then 0.
  • Undefined values are converted into 0.

Examples:

SituationFormulaPost-processed resultComment
The GET variable gender is maleGETvariable("gender")0because male is forced into 0
The GET variable gender was not recordedGETvariable("gender")0because the empty string is forced into 0
The GET variable age is 20GETvariable("age")20because age is converted into the number 20
"3" + 58because 3 is forced into the number 3
"male" + " bird"0because both string values are forced into 0
"1"1because the string value is converted into a number
"one"0because the string value could not be converted into a number