0 votes
in SoSci Survey (English) by s237955 (180 points)
edited by s237955

Hi all,

I am wondering how to assign a group with intermediate range of values? For instance, following code computes and assigns groups with High and Low values on a scale.

//Stop/ continue survey if score is below/ above cut off score. 
 //Assign groups: High(ALPHA)/ Low(BETA)/ Intermediate(GAMMA) 
       
        if (value('A002_01') >= 72) 
            {
              html('<p>, <h1> Danke für Ihre Teilnahme. Diese Umfrage endet hier. Bitte notieren Sie sich diese Nummer für zukünftige Referenzzwecke. <span style="color: #009900"> <u> ALPHA Nr. '.caseNumber().' '.caseSerial().'</span>','<u>','</p>', '<h1>');
              $group = 1;
              put('ALPHA',$group);
            //  goToPage('next'); 

            }  else if (value('A002_01') <= 51) 
            {
              html('<p>, <h1> Danke für Ihre Teilnahme. Diese Umfrage endet hier. Bitte notieren Sie sich diese Nummer für zukünftige Referenzzwecke. <span style="color: #009900"> <u> BETA  Nr. '.caseNumber().' '.caseSerial().'</span>','<u>','</p>', '<h1>');
              $group = 2; 
              put('BETA',$group);

Now, I would like to assign a GAMMA as intermediate group to those obtaining a score ranging between 52-71. I tried to achieve this with the following code which computes and show score only less and greater than but not within the range from 52 to 71. How to do the same with range of score? Searched forum and documentation but couldn't find a way. Thanks for your suggestions!

}  else ((value('A002_01')   >=52) and (value('A002_01')   <=71));
                {
                  html('<p>, <h1> Danke für Ihre Teilnahme. Diese Umfrage endet hier. Bitte notieren Sie sich diese Nummer für zukünftige Referenzzwecke. <span style="color: #009900"> <u> 
GAMMA  Nr. '.caseNumber().' '.caseSerial().'</span>','<u>','</p>', '<h1>');
              $group = 3; 
              put('GAMMA',$group);
            }
            //  buttonHide();  // Hide the next-button
            //  pageStop();  // In case other content shows with the filter
            //<h1> to Bold text, <u> to Underline

by SoSci Survey (327k points)
> How to do the same with range of score?

I am afraid that I do not understand the question.

An IF filter always had a condition, and this is met or not. What condition do you want to check? And what values failed your IF structure as you already created it?
by s237955 (180 points)
Is there any symbol/ notation to compute a 'Between value' e.g. a range as continuum?
All conditions are meeting but the 3rd one I want in a different way.
1. Message with ALPHA in the screenshot must appear only when score>= 72.

2. Message with BETA in the screenshot must appear only when score<= 51.

3. Message with GAMMA in the screenshot must appear only when score is between 52 to 71.

If you notice in the screenshot msg with BETA and GAMMA are displayed together when one scores either <= 51 or <= 71. What I need to change in the code that groups don't clash and do not appear together? That 3rd condition should only meet when score is between 52 to 71?

I understand above code is correct but I need to change it in a way that it only saves and shows GAMMA if score is only in a range of 52-71, not that if I put  <= 71 it counts all values from 71 to 0.

1 Answer

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

If you notice in the screenshot msg with BETA and GAMMA are displayed together

Okay, that's probably a simple issue with the code that you did NOT post ;)

Make sure to use ELSEIF. The basic application is:

if ($value >= 72) {
  // alpha
} elseif ($value <= 51) {
  // beta
} else {
  // gamma
}

Or if you want separate conditions:

if ($value >= 72) {
  // alpha
}
if ($value <= 51) {
  // beta
}
if (($value < 72) && ($value > 51)) {
  // gamma
}

Note that I wrote < 72 instead of <= 72

by s237955 (180 points)
edited by s237955
It's still showing the same, both groups together.

Full code:
//Compute scale indices
$sum = valueSum('A001');

//AI index
$sumAI = valueSum('A001', array(5,6,9,11,20,24,26,28));

//MI index
$sumMI = valueSum('A001', array(2,3,4,16,17,19,21,22,23,25,30));

//NI index
$sumNI = valueSum('A001', array(1,7,8,10,12,13,14,15,18,27,29));

//Save results (indices) in data file
put('A002_01',$sum);
put('A003_01',$sumAI);
put('A004_01',$sumMI);
put('A005_01',$sumNI);

//Stop/continue survey if score is below/above cut off.
//Assign groups: High(ALPHA)/Low(BETA)/Intermediate(GAMMA)

if (value('A002_01') >= 72)
{
  html('<p>, <h1> Danke für Ihre Teilnahme. Diese Umfrage endet hier. Bitte notieren Sie sich diese Nummer für zukünftige Referenzzwecke. <span style="color: #009900"> <u> ALPHA Nr. '.caseNumber().' '.caseSerial().'</span>','<u>','</p>', '<h1>');
  $group = 1;
  put('ALPHA',$group);
//  goToPage('next'); ,$group = ALPHA; ,$group = BETA;put('BETA', $group);put('ALPHA', $group);
}  elseif (value('A002_01') <= 51)
{
  html('<p>, <h1> Danke für Ihre Teilnahme. Diese Umfrage endet hier. Bitte notieren Sie sich diese Nummer für zukünftige Referenzzwecke. <span style="color: #009900"> <u> BETA  Nr. '.caseNumber().' '.caseSerial().'</span>','<u>','</p>', '<h1>');
  $group = 2;
  put('BETA',$group);

}  else((value('A002_01')<72)&&(value('A002_01')>52));
{
  html('<p>, <h1> Danke für Ihre Teilnahme. Diese Umfrage endet hier. Bitte notieren Sie sich diese Nummer für zukünftige Referenzzwecke. <span style="color: #009900"> <u> GAMMA  Nr. '.caseNumber().' '.caseSerial().'</span>','<u>','</p>', '<h1>');
  $group = 3;
  put('GAMMA',$group);
}


//  buttonHide();  // Hide the next-button
//  pageStop();  // In case other content shows with the filter
//<h1> to Bold text, <u> to Underline
by SoSci Survey (327k points)
Please watch your semicolons:

}  else((value('A002_01')<72)&&(value('A002_01')>52));

First, else dies NOT expect any condition behind, so you could also write:

}  else;

The semicolon ends the statement.

So the last block runs always. Because, it's just a statement outside of any IF.

So, what you neded to change is

}  else((value('A002_01')<72)&&(value('A002_01')>52));
{

to

} else {
by s237955 (180 points)
It works like a charm, thanks a lot!

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

...