How to calculate the mean of several variables when you have DK/NA values
To calculate the average of several variables, you need to know what you want to do when you have DK values. When you have at least one DK/NA value, in Askia Analyse or in AskiaVista, the sum of variables will be equal to DK:
DK/NA + Var2 + Var3 = DK
Var1 + DK/NA + Var3 = DK
Var1 + Var2 + DK/NA = DK
So, to handle the interview with a DK response, you have two possibilities:
1. Removing the interview
If you have at least one DK/NA value, you want to remove the full interview from the average calculation. (Calculated variable Numeric by script):
Dim arrQs As QuestionArray
arrQs.Push(^Q1^).Push(^Q2^).Push(^Q3^)
Dim arrVals = {}
Dim i
For i = 1 to arrQs.Count
If arrQs[i].Value <> DK Then
arrVals.Push(arrQs[i].Value.ToNumber())
Else
arrVals = {}
Exit for
Endif
Next i
If arrVals has {DK} Then
Return DK
Else
Return arrVals.Sum()/arrVals.Count
EndIf
2. Keep the interview and ignore the variable
You have at least one DK/NA value, you exclude the variable from the calculation but you keep the interview for other valid variables (calculated variable numeric by script):
Dim arrQs As QuestionArray
arrQs.Push(^Q1^).Push(^Q2^).Push(^Q3^)
Dim arrVals = {}
Dim i
For i = 1 to arrQs.Count
If arrQs[i].Value <> NR Then
arrVals.Push(arrQs[i].Value.ToNumber())
Endif
Next i
Return arrVals.Sum()/arrVals.Count
You can also highlight all three variables in the Question tree > Create loop. The resulting looped variables can give you some additional flexibility to analyse the aggregated data of the source variables.