Formulas for calculating respondent weightings
Formulas can be used when calculating respondent weightings 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 using the
answer(question_id, [item_id], [stimulus_id])function, then multiply it by a scaling factor.If you wanted respondents to be weighted based on whether their age is above 50 (weight of
1), exactly 50 (weight of0.5), or below 50 (weight0.1), the formula will be:
ifs(answer(1559304)>50,1,answer(1559304)==50,0.5,0.1)
or, almost equivalently:
(answer(1559304)>50) + (answer(1559304)==50)*0.5 + (answer(1559304)<50 & answer(1559304)>0)*0.1
Post-processing rule for respondent weightings
There is a special post-processing rule that applies to the output of formulas used in respondent weightings: The final value x from the formula language is wrapped into naTo0(toNumber(x)).
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 | |
undefined | 0 | because undefined values are converted into 0 |