Have an idea?

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

Dynamic Listing

Hello, we are trying to create 2 dynamic lists referring to one another. The first one, namely NewEqtWTPDyn is constructed with taking its members from the answers of the desirability questions. ItemList2 stands for the list that Desir questions are referring whether the participant is interested or not interested in that particular item. For example, in Desir1 question, we are asking participant if he/she is interested in the first item in ItemList2. In Desir2, the second item in ItemList2, and so on. The code of the list is as follows:

Begin Unverified Perl

   
 if (GETVALUE("Desir1") == 2)
  {  
   ADD("ItemList2",1);
  }
if (GETVALUE("Desir2") == 2)
  {  
   ADD("ItemList2",2);
  }
if (GETVALUE("Desir3") == 2)
  {  
   ADD("ItemList2",3);
  }
if (GETVALUE("Desir4") == 2)
  {  
   ADD("ItemList2",4);
  }
if (GETVALUE("Desir5") == 2)
  {  
   ADD("ItemList2",5);
  }
if (GETVALUE("Desir6") == 2)
  {  
   ADD("ItemList2",6);
  }
if (GETVALUE("Desir7") == 2)
  {  
   ADD("ItemList2",7);
  }
if (GETVALUE("Desir8") == 2)
  {  
   ADD("ItemList2",8);
  }
if (GETVALUE("Desir9") == 2)
  {  
   ADD("ItemList2",9);
  }
if (GETVALUE("Desir10") == 2)
  {  
   ADD("ItemList2",10);
  }
if (GETVALUE("Desir11") == 2)
  {  
   ADD("ItemList2",11);
  }
if (GETVALUE("Desir12") == 2)
  {  
   ADD("ItemList2",12);
  }
if (GETVALUE("Desir13") == 2)
  {  
   ADD("ItemList2",13);
  }
if (GETVALUE("Desir14") == 2)
  {  
   ADD("ItemList2",14);
  }
if (GETVALUE("Desir15") == 2)
  {  
   ADD("ItemList2",15);
  }
if (GETVALUE("Desir16") == 2)
  {  
   ADD("ItemList2",16);
  }
if (GETVALUE("Desir17") == 2)
  {  
   ADD("ItemList2",17);
  }
if (GETVALUE("Desir18") == 2)
  {  
   ADD("ItemList2",18);
  }
if (GETVALUE("Desir19") == 2)
  {  
   ADD("ItemList2",19);
  }
if (GETVALUE("Desir20") == 2)
  {  
   ADD("ItemList2",20);
  }

End unverified

Also, we selected 15 particular items in ItemList2. Then, we are trying to find if any of this 15 items are also chosen as "I'm interested"(DesirX==2) in any of the Desir questions. So we created another dynamic list, namely FinalEqtWTPDyn as follows:

Begin Unverified Perl
  
 if (LISTHASPARENTMEMBER("NewEqtWTPDyn",11))
  {  
   ADD("ItemList2",11);
  }
 if (LISTHASPARENTMEMBER("NewEqtWTPDyn",14))
  {  
   ADD("ItemList2",14);
  }
if (LISTHASPARENTMEMBER("NewEqtWTPDyn",15))
  {  
   ADD("ItemList2",15);
  }
  if (LISTHASPARENTMEMBER("NewEqtWTPDyn",16))
  {  
   ADD("ItemList2",16);
  }
  if (LISTHASPARENTMEMBER("NewEqtWTPDyn",19))
  {  
   ADD("ItemList2",19);
  }
  if (LISTHASPARENTMEMBER("NewEqtWTPDyn",20))
  {  
   ADD("ItemList2",20);
  }
  if (LISTHASPARENTMEMBER("NewEqtWTPDyn",21))
  {  
   ADD("ItemList2",21);
  }
  if (LISTHASPARENTMEMBER("NewEqtWTPDyn",28))
  {  
   ADD("ItemList2",28);
  }
  if (LISTHASPARENTMEMBER("NewEqtWTPDyn",30))
  {  
   ADD("ItemList2",30);
  }
  if (LISTHASPARENTMEMBER("NewEqtWTPDyn",38))
  {  
   ADD("ItemList2",38);
  }
  if (LISTHASPARENTMEMBER("NewEqtWTPDyn",41))
  {  
   ADD("ItemList2",41);
  }
  if (LISTHASPARENTMEMBER("NewEqtWTPDyn",44))
  {  
   ADD("ItemList2",44);
  }
  if (LISTHASPARENTMEMBER("NewEqtWTPDyn",53))
  {  
   ADD("ItemList2",53);
  }
  if (LISTHASPARENTMEMBER("NewEqtWTPDyn",57))
  {  
   ADD("ItemList2",57);
  }
  if (LISTHASPARENTMEMBER("NewEqtWTPDyn",61))
  {  
   ADD("ItemList2",61);
  }

  RANDOMIZE
   End Unverified

Then, we are trying to reference a random member of this list by referring to it in a question with the code:

[%ListLabel (FinalEqtWTPDyn, 1)%]

BUT IT DOESNT WORK! We're trying to figure out the problem for several hours with nothing came up. Are there anyone to help us on this issue?

Huuuge thanks in advance!

Can
asked Apr 8 by CaEr (450 points)
edited Apr 8 by CaEr

1 Answer

0 votes
To start with, let's help you tidy up the "NewEqtWTPDyn" constructed list ...
Begin Unverified Perl

 my $i=1;

 for($i=1; $i<=20; $i++)
  {
   if (GETVALUE("Desir".$i)==2)
    {  
     ADD("ItemList2",$i);
    }  
  }

End Unverified

I also noticed the "FinalEqtWTPDyn" constructed list is referring to the "NewEqtWTPDyn" constructed list.  The "NewEqtWTPDyn" constructed list will only capture items 1-20 (based on your code). Your "FinalEqtWTPDyn" constructed list is searching for 6 items numbered 20 or below, but is also searching for 9 further items above 20 (which they will never find based on your code). Does that make sense?

Your "FinalEqtWTPDyn" constructed list should have RANDOMIZE(); and not RANDOMIZE.

So when you say it does not work, are you seeing any errors? Does the survey run okay without crashing? Or are you seeing blank displayed for the ListLabel command?
answered Apr 8 by Paul Moon Platinum (91,280 points)
edited Apr 8 by Paul Moon
Thank you for your fast reply Paul. We're not seeing any errors, survey runs without crashing and we are seeing a blank display for the listlabel command. Also we created a select question to test the second list but that question is also automatically skipped, because of having no members i suppose.
Please re-read my post. I added further comments.
"FinalEqtWTPDyn" will only ever find items 20 or below in "NewEqtWTPDyn". It will never find items above 20.
Oh, the first desir part was going until 65 but i shortened code not to make it a very messy question. So you can think the first list is constructed as follows:

Begin Unverified Perl
 
 my $i=1;
 
 for($i=1; $i<=65; $i++)
  {
   if (GETVALUE("Desir".$i)==2)
    {  
     ADD("ItemList2",$i);
    }  
  }
 
End Unverified
Conduct the same test to see if "NewEqtWTPDyn" is working correctly.

Get "NewEqtWTPDyn" working first, then move on to "FinalEqtWTPDyn" next.
OK, that makes sense. You can use the looped version to keep the programming down to a minimum.
we did test the first list and yeah, it works, the problem is with the second list
Did you fix the randomize function?
And what you should do is create a TEST1 select question that displays the items from "NewEqtWTPDyn". Use this as your list.

Then the next question should be a TEST2 select question that displays the items from "FinalEqtWTPDyn". Use this as your list.

I just want to ensure that "NewEqtWTPDyn" has worked correctly and you have used it in your survey. Then I want to see if "FinalEqtWTPDyn" picks up on the "NewEqtWTPDyn" list at all.
I can also take a look at your ssi file (or a trimmed down version of it) if you like?
Huge thanks on your efforts and kind help request. We've figured this out by eliminating the second list and using the first one as follows:

Begin Unverified Perl

   
 if (GETVALUE("Desir11") == 2)
  {  
   ADD("ItemList2",11);
  }
if (GETVALUE("Desir14") == 2)
  {  
   ADD("ItemList2",14);
  }
if (GETVALUE("Desir15") == 2)
  {  
   ADD("ItemList2",15);
  }
if (GETVALUE("Desir16") == 2)
  {  
   ADD("ItemList2",16);
  }
if (GETVALUE("Desir19") == 2)
  {  
   ADD("ItemList2",19);
  }
if (GETVALUE("Desir20") == 2)
  {  
   ADD("ItemList2",20);
  }
if (GETVALUE("Desir21") == 2)
  {  
   ADD("ItemList2",21);
  }
if (GETVALUE("Desir28") == 2)
  {  
   ADD("ItemList2",28);
  }
if (GETVALUE("Desir30") == 2)
  {  
   ADD("ItemList2",30);
  }
if (GETVALUE("Desir38") == 2)
  {  
   ADD("ItemList2",38);
  }
if (GETVALUE("Desir41") == 2)
  {  
   ADD("ItemList2",41);
  }
if (GETVALUE("Desir44") == 2)
  {  
   ADD("ItemList2",44);
  }
if (GETVALUE("Desir53") == 2)
  {  
   ADD("ItemList2",53);
  }
if (GETVALUE("Desir57") == 2)
  {  
   ADD("ItemList2",57);
  }
if (GETVALUE("Desir61") == 2)
  {  
   ADD("ItemList2",61);
  }

RANDOMIZE ();


 
End Unverified

Which is basically checking only the 15 items' desire questions whether it is selected interested or not. Then, as its randomized, we are referring it in another question with [%ListLabel (NewEqptWTPDyn, 1)%].

Thanks again!
That will certainly work. There's usually a number of methods available to get the task completed successfully.
...