Have an idea?

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

Randomize a Constructed List

Hello,

I am trying to randomize a constructed list where the order is kept the same as another randomized list.

My first list is based on the parent list Q9List and the syntax that I am using is


ADD (Q9List,1,15)
Randomize (RespNum() * 1000 + PageNumber(),1,12)



My second list is based on the parent list Q9List and the syntax that I am using is:

Begin Unverified Perl

if (GETVALUE ("Q9_r1_c1") == 1 || GETVALUE ("Q9_r1_c2") == 1)
{
    ADD ("Q9List",1);
}
if (GETVALUE ("Q9_r2_c1") == 1 || GETVALUE ("Q9_r2_c2") == 1)
{
    ADD ("Q9List",2);
}

if (GETVALUE ("Q9_r3_c1") == 1 || GETVALUE ("Q9_r3_c2") == 1)
{
    ADD ("Q9List",3);
}

if (GETVALUE ("Q9_r4_c1") == 1 || GETVALUE ("Q9_r4_c2") == 1)
{
    ADD ("Q9List",4);
}

if (GETVALUE ("Q9_r5_c1") == 1 || GETVALUE ("Q9_r5_c2") == 1)
{
    ADD ("Q9List",5);
}

if (GETVALUE ("Q9_r6_c1") == 1 || GETVALUE ("Q9_r6_c2") == 1)
{
    ADD ("Q9List",6);
}

if (GETVALUE ("Q9_r7_c1") == 1 || GETVALUE ("Q9_r7_c2") == 1)
{
    ADD ("Q9List",7);
}

if (GETVALUE ("Q9_r8_c1") == 1 || GETVALUE ("Q9_r8_c2") == 1)
{
    ADD ("Q9List",8);
}

if (GETVALUE ("Q9_r9_c1") == 1 || GETVALUE ("Q9_r9_c2") == 1)
{
    ADD ("Q9List",9);
}

if (GETVALUE ("Q9_r10_c1") == 1 || GETVALUE ("Q9_r10_c2") == 1)
{
    ADD ("Q9List",10);
}

if (GETVALUE ("Q9_r11_c1") == 1 || GETVALUE ("Q9_r11_c2") == 1)
{
    ADD ("Q9List",11);
}

if (GETVALUE ("Q9_r12_c1") == 1 || GETVALUE ("Q9_r12_c2") == 1)
{
    ADD ("Q9List",12);
}


End Unverified

Randomize (RespNum() * 1000 + PageNumber(),1,12)


Begin Unverified Perl

if (GETVALUE ("Q9_r13_c1") == 1 || GETVALUE ("Q9_r13_c2") == 1)
{
    ADD ("Q9List",16);
}

if (GETVALUE ("Q9_r14_c1") == 1 || GETVALUE ("Q9_r14_c2") == 1)
{
    ADD ("Q9List",17);
}

if (GETVALUE ("Q9_r15_c1") == 1 || GETVALUE ("Q9_r15_c2") == 1)
{
    ADD ("Q9List",18);
}

End Unverified


But the code is not working.  

Thank you for your help
asked Mar 14 by Sandy

1 Answer

0 votes
I’m not sure what the second Perl set is doing, but the || GETVALUE part is incomplete on each statement. So that’s thing #1.

The second thing is that randomizing a set of 10 things will give you completely different ordering than randomizing a set of nine things, even with the same random seed. In your case, I suspect you have a different number of items and probably a different seed since you’re probably calling it on a different page than the first list build. Probably the easiest way to get around this is to just add the first constructed list to the second constructed list and then use the unverified Perl to remove things that don’t belong instead of adding things that do belong. That way you’re guaranteed the same order even if the list length and page number are different.
answered Mar 14 by Aaron Hill
Hi Aaron,

Thank you for your response.

The second Perl set is adding the others to the list.  I don't wish for those answer choices to be randomize.

How is the || GETVALUE part incomplete on each statement?  I don't see it.

Randomizing a set to 10 things will give you completely different ordering than randomizing a set to nine things.   I understand and that makes sense.  I will try your suggestion regarding adding the the first constructed list to the second constructed list then using unverified Perl to remove things that don't belong.


Thank you
I thought I would jump in as Aaron is amongst the AM hours at the moment. I'm assuming you are in Utah Aaron?

I agree with Aaron's approach of copying the constructed list from the earlier question and then removing items. This will keep the randomised order the same. It's a neat approach.

Let's call your first constructed list List1ConList. It displays and randomises your items in the earlier question.

Now let's create List2ConList ...

This list will copy the first list in the same order and then start removing items based on your criteria.
ADD(List1ConList)

Begin Unverified Perl

 my $i=1;

 for($i=1; $i<=15; $i++)
  {
   if (GETVALUE("Q9_r".$i."_c1")!=1 && GETVALUE("Q9_r".$i."_c2")!=1)
    {  
     if ($i<13)
      {
       ADD("Q9List",$i);
      }
     else
      {
       ADD("Q9List",$i+3);
      }
    }  
  }

End Unverified

Give it a try. Good luck.
Thank you both! I used Aaron's suggestion on removing the codes that did n't  belong.

Thank you Paul for your syntax.  This is great!  I love seeing a shorter way of doing things.  I will use this approach on other surveys.

Have a great day to you both
I'm off to bed, but I reckon Aaron is about to greet the morning. Enjoy the day too Sandy.

Aaron was spot on with the structure - copy list and remove. He knows this stuff upsidedown.
...