0 votes
in SoSci Survey (English) by s053863 (130 points)

Hello

I have a new requirement for my questionnaire, where selection answers should have different points than the default ones. The valueSum() simply sums the default values (1,2,3,4,5).

What would be the simplest way to sum values so that custom values (i.e. 1.3, 1.8, 2.9, 4.4, 5) for each option would be applied.

Only way I could figure out is to use value() for each question separately and then use the custom multiplier(s) for the result. But just makes me think that maybe there is some easier way because valueSum() returns float according to documentation.

Any advices are welcome. Thanks!

Olli

1 Answer

+1 vote
by SoSci Survey (327k points)
selected by s053863
 
Best answer

Only way I could figure out is to use value() for each question separately and then use the custom multiplier(s) for the result.

If you use a FOR loop for that, it's not that bad. And it's probably easier than playing with frequency arrays.However, valueList() will save you at least typing the variable names.

$values = valueList('AB01');
$sum = 0;
$cnt = 0;
$recode = array(1 => 1.3, 2 => 1.8, 3 => 2.9, 4 => 4.4, 5 => 5);
foreach ($values as $value) {
  if (isset($recode[$value])) {
    $sum+= $recode[$value];
    $cnt++;
  }
}
html('<p>Sum '.$sum.'</p>');

The $cnt only comes into play, if you need a mean value and have missing data.

by s053863 (130 points)
Thanks!

I think I just needed confirmation so that I haven't missed anything obvious.

Anyway, thanks for the code snippet, used that as a skeleton, and indeed, valueList() worked well!

Willkommen im Online-Support von SoSci Survey.

Hier bekommen Sie schnelle und fundierte Antworten von anderen Projektleitern und direkt von SoSci Survey.

→ Eine Frage stellen


Welcome to the SoSci Survey online support.

Simply ask a question to quickly get answers from other professionals, and directly from SoSci Survey.

→ Ask a Question

...