Have an idea?

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

Create a constructed list based on answers - then listlabel that chooses one item randomly

I have a survey with 4 travel-situations - we want to randomly put respondents in 1 of the situations. We also have some conditions. We ask how often they they travel in each situation - they should then be able to get one of the situations that they answered 1-6 for. So these are 4 singel questions(per situation) with 8 alternatives (frequensy).

I would then in the followng questions say something like, imagine that you... and then use  [%ListLabel()%] to insert one of the situations. But here its tricky because I cant just type in an answer from a question.

Do you know how I could solve this? If its possible to make a constructed list that I could insert in  the listlabel, that would randomly insert one of the situations given that they answered 1-6 for the situation.

Best, Line
asked Oct 2, 2020 by Linebje (420 points)
Just to be clear, you want to select from the 4 travel types where 1-6 was mentioned. If 7-8 was mentioned for any travel types, do not include in the selection process. Is that correct?

Once you have randomly selected  a travel type, you would like to display that travel type in another question?

Where you ask the travel frequency, is that in a grid or 4 separate select questions?

Have I missed anything?

2 Answers

0 votes
You can create a constructed list (say random1situation) which will have conditions if they belong to the required category (1-6).
It is possible that more than one situation qualifies to the condition, so to have just one random situation out of the qualified situation, you can add Randomize() then ListMax(1) function in the constructed list which will have only 1 situation from the qualified ones.
So, constructed list has now only one situation which can be called in the question text using below ssi script.
[%ListLabel(random1situation,1)%]
It is possible that a respondent do not choose 1-6 for any situation, so in that case you can skip following questions or terminate the respondent as per your requirement. The logic that can be used here.
Condition :: ListLength(random1situation)<1

I hope this answers your question.

Regards,
Rahul Mittal
answered Oct 2, 2020 by Rahul Mittal Gold (11,635 points)
You can simply use below code in the constructed list:

AIL(Q1,7)
Randomize()
ListMax(1)
So the question is single select. I have 1qa, 1qb, 1qc and 1qd where I ask about situation as a text and then they rate frequency from 1-8 (they use the same list (1qaList). I think I have to make a predefined list with the 4 situations and somehow combine this with the constructed list that qualifies for each situation. So a constructed list that says if q1a<=6 then add situation(from predefined list), if q1b <=6 then add situation etc. (Im not very experienced at perl, so just not sure how). And then I guess randomize and listmax(1) would work for the only get 1 part.
Add a predefined list with 4 situations as list members.
Then, create a constructed list "random1situation" and call the above created list as parent list.

Use below code:

Begin Unverified Perl
if(VALUE("q1a")>=1 && VALUE("q1a")<=6){ADD(PARENTLISTNAME(),1);}
if(VALUE("q1b")>=1 && VALUE("q1b")<=6){ADD(PARENTLISTNAME(),2);}
if(VALUE("q1c")>=1 && VALUE("q1c")<=6){ADD(PARENTLISTNAME(),3);}
if(VALUE("q1d")>=1 && VALUE("q1d")<=6){ADD(PARENTLISTNAME(),4);}
RANDOMIZE();
LISTMAX(1);
End Unverified


So, constructed list has now only one situation which can be called in the question text using below ssi script.
[%ListLabel(random1situation,1)%]
It is possible that a respondent do not choose 1-6 for any situation, so in that case you can skip following questions or terminate the respondent as per your requirement. The logic that can be used here.
Condition :: ListLength(random1situation)<1
Works perfectly! Thanks :)
0 votes
This is an example of a constructed list that will extract travel types from a row direction grid question called "Q1". I have assumed the list at Q1 to be called "TravelTypeList".
Begin Unverified Perl

 my $i=1;

 for($i=1; $i<=4; $i++)
  {
   if (VALUE("Q1_r".$i)>=1 && VALUE("Q1_r".$i)<=6)
    {  
     ADD("TravelTypeList",$i);
    }  
  }

 RANDOMIZE();
 LISTMAX(1);

End Unverified

Only one of the valid travel types will be randomly selected.

If we call this constructed list "TravelSelectedList", simply use ...
[%ListLabel(TravelSelectedList,1)%] to display the selected travel type at any future questions.
answered Oct 2, 2020 by Paul Moon Platinum (89,980 points)
So the question is single select. I have 1qa, 1qb, 1qc and 1qd where I ask about situation as a text and then they rate frequency from 1-8 (they use the same list (1qaList). I think I have to make a predefined list with the 4 situations and somehow combine this with the constructed list that qualifies for each situation. So a constructed list that says if q1a<=6 then add situation(from predefined list), if q1b <=6 then add situation etc. (Im not very experienced at perl, so just not sure how). And then I guess randomize and listmax(1) would work for the only get 1 part.
Got this from Rahul - worked perfect :) thanks for the help

Begin Unverified Perl
if(VALUE("q1a")>=1 && VALUE("q1a")<=6){ADD(PARENTLISTNAME(),1);}
if(VALUE("q1b")>=1 && VALUE("q1b")<=6){ADD(PARENTLISTNAME(),2);}
if(VALUE("q1c")>=1 && VALUE("q1c")<=6){ADD(PARENTLISTNAME(),3);}
if(VALUE("q1d")>=1 && VALUE("q1d")<=6){ADD(PARENTLISTNAME(),4);}
RANDOMIZE();
LISTMAX(1);
End Unverified
Rahul has provided the constructed list solution given your 4 travel type questions are select questions, rather than a grid question.

I just noticed the question names were slightly incorrect ...
Begin Unverified Perl

if(VALUE("1qa")>=1 && VALUE("1qa")<=6){ADD("1qaList",1);}
if(VALUE("1qb")>=1 && VALUE("1qb")<=6){ADD("1qaList",2);}
if(VALUE("1qc")>=1 && VALUE("1qc")<=6){ADD("1qaList",3);}
if(VALUE("1qd")>=1 && VALUE("1qd")<=6){ADD("1qaList",4);}

RANDOMIZE();
LISTMAX(1);

End Unverified

Thanks Rahul for chipping in. Much appreciated mate.
Thanks Paul.

I changed the question names intentionally because sawtooth will not allow you to add a question starting with numeric.

"Name cannot begin with numbers or other invalid characters".
OK, got it.

I must say I have never had a need to name a question beginning with a number, so I wasn't aware it was illegal.

As long as Line uses the question numbers defined, that solution will be okay.
...