Have an idea?

Visit Sawtooth Software Feedback to share your ideas on how we can improve our products.

Calculating the average value of a 5-item grid.

Hi,

Im currently designing my survey and I have a grid question where respondents need to select how much they agree/disagree to 5 statements (1-strongly disagree, 5-strongly agree). I want to calculate a numeric variable that computes the average value for each respondent since I want to include this continuous variable as covariate later in my analysis.

I searched in the forum and I found a possible way to calculate such variable by creating a new variable within a Free Format question, and make it a "hidden" type variable.  Then in the html box add [% (Q1 + Q2 + Q3 + Q4 + Q5)/5 %] this script. I followed these instructions but instead of having different questions within the brackets I had the different rows as followed:

[% (IndScale_r1 + IndScale_r2 + IndScale_r3 + IndScale_r4 + IndScale_r5) /5 %]

The problem is that this doesnt seem to work because when I filled in a questionnaire and downloaded the data the column refers to the new variable is empty. So no value was calculated. In addition, when I filled in the survey I noticed that in the place where the new variable was added a "0" appeared. That is kind of weird since I clicked at the "hidden" format.

Am I doing something wrong? Is there another way to calculate the average value per respondent for a grid?

Thank you :)
asked Apr 12 by anonymous

2 Answers

+1 vote
You could create a pass-in variable and use setvalue.  Say you create a pass-n variable called GRIDAVG.  Then, in the header or footer of a questions after those 5 that all respondents will see, use this script.

[% SetValue(GRIDAVG,(Q1 + Q2 + Q3 + Q4 + Q5)/5) %]

If you are doing this from answers on a grid question, make sure that you use the correct variable names for your rows.
answered Apr 12 by Jay Rutherford Gold (32,415 points)
Thank you both so much for replying so fast.

I wrote the script exactly how you've written it Paul,

[% SetValue(IndAverage,Round((IndScale_r1 + IndScale_r2 + IndScale_r3 + IndScale_r4 + IndScale_r5 + IndScale_r6)/6),1)%]
But it gives me a wrong message :
The function call "SetValue" contains an invalid number of arguments or an argument with an incorrect type.

Can you see a mistake in my script because I think is the same with yours?
I believe it needs to be:

[% SetValue(IndAverage,Round((IndScale_r1 + IndScale_r2 + IndScale_r3 + IndScale_r4 + IndScale_r5 + IndScale_r6)/6,1))%]

The ,1 should be inside the ROUND() tag.
Thanks Jay for correcting my syntax.
It worked!! Thank you both so much
You're welcome.  Glad we were able to help you sort it out and point out a few things for you to add to your knowledge base!
0 votes
You can use the SetValue function which caters for this very need.

Define a variable called GridAverage in the Pass-In fields and define it as a whole number.

Pop this script into the footer of an appropriate question (one that is not skipped).

[%SetValue(GridAverage,(Q1+Q2+Q3+Q4+Q5)/5)%]

Replace the above example questions with you question numbers.

If you want to get a little fancy, you can use the ROUND function to clean up the decimal places.

ROUND (NUMBER,#DECIMALS)
answered Apr 12 by Paul Moon Platinum (75,380 points)
...