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 . 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
or1
. - Text values are converted into numbers, and if impossible, then
0
. - Undefined values are converted into
0
.
Examples:
Situation | Formula | Post-processed result | Comment |
---|---|---|---|
The GET variable gender is male | GETvariable("gender") | 0 | because male is forced into 0 |
The GET variable gender was not recorded | GETvariable("gender") | 0 | because the empty string is forced into 0 |
The GET variable age is 20 | GETvariable("age") | 20 | because age is converted into the number 20 |
"3" + 5 | 8 | because 3 is forced into the number 3 | |
"male" + " bird" | 0 | because both string values are forced into 0 | |
"1" | 1 | because the string value is converted into a number | |
"one" | 0 | because the string value could not be converted into a number |