Have an idea?

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

Block Randomization doesn't work

My study contains 10 blocks of questions.
The respondents should either conduct block 1-5 or block 6-10.
So i've tried my best and created a parent list called "BlockList" with 10 predefined list members. (1,2,3,4... and so on).

Afterwards i created a constructed list based on BlockList with the following code:

Begin Unverified Perl
my$RandNum=SYSRAND(1,2);
          if($RandNum==1)
          {
                    ADD("BlockList",1,2,3,4,5);
          }
          else
          {
                    ADD("BlockList",6,7,8,9,10);
          }
End Unverified
asked Jan 11, 2022 by Honeybadger Bronze (890 points)

1 Answer

0 votes
Try this ...
Begin Unverified Perl

my $RandNum=SYSRAND(1,2);

 if($RandNum==1)
   {
    ADD("BlockList",1,5);
   }
 else
   {
    ADD("BlockList",6,10);
   }
End Unverified
answered Jan 11, 2022 by Paul Moon Platinum (101,405 points)
Thanks Paul, it works. But now I need the same amount of respondents in group 1 (block 1 to 5) and group 2 (block 6 to 10).

My experience with SysRand is that it is totally random.
Sometimes there are 20 surveys in a row which conduct block 6 to 10

Any opportunities to weight the random number in the same way.

Thanks!
You can use a quota question and apply the least fill method.

Let's say the quota question is called "QTBlock" and QTBlock=1 refers to blocks 1-5 and QTBlock=2 refers to blocks 6-10.

So in your Perl Script, change "$RandNum==1" to "VALUE("QTBlock")==1".

That should now incorporate the equal allocation across the blocks.
You mean, the relation betwenn quota and randomized block came through adaption of the Perl Code in Constructed List with Value(...) instead of RandNum.

I refer those values to the value of the quota?
The least fill quota question will determine which block to select (block 1 or 2 based on the quota counts at the time). The constructed list will then be used for block selection by saying if quota block 1 show 1-5, otherwise show 6-10.

So use the constructed list in the same way when you were using the random approach.
As I said I have to include a connection between quotas and constructed list?
I am a bit confused to get on it… maybe you could help me a bit more if I send you my Zip tomorrow.

I would be very grateful for your engagement so far.
I'm on a family holiday at the moment so I am somewhat limited for the next few days.

I'll try to explain it step by step.

1/ Create a quota question and call it QTBlock.
2/ Define 2 cells - 1=Block 1 and 2=Block 2.
3/ Set your cell limits for both quota cells.
4/ Set to always qualify for both quota cells
5/ Select any of the "Least fill" options for "check for cell membership". If your targets are the same for blocks 1+2, any of these will work.

So the above will have the quota question totally setup. This question will save the block selected based on a least fill.

Now use the same constructed list and the same block setup you had before for the randomised approach, but change the condition in the constructed list as follows ...

"$RandNum==1" to "VALUE("QTBlock")==1".

So now your constructed list will select from the quota question rather than selecting randomly.

Does that help?

I can create a ZIP file on Friday when I return from my holiday. Let me know if you need that sent through.

Apologies for any confusion.

Regards Paul.
Thanks. I will send my code here, it is a bit more complicated  - just explained it with two blocks for understanding.

Begin Unverified Perl
    if(VALUE("QUOTAGROUP")==1)
    {
        ADD("BlockList",1,3);
        RANDOMIZE();
        ADD("BlockList",5);
    }
    if(VALUE("QUOTAGROUP")==2)
    {
        ADD("BlockList",1,2);
        ADD("BlockList",4);
        RANDOMIZE();
        ADD("BlockList",5);
    }
    if(VALUE("QUOTAGROUP")==3)
    {
        ADD("BlockList",6,8);
        RANDOMIZE();
        ADD("BlockList",10);
    }
    else
    {
        ADD("BlockList",6,7);
        ADD("BlockList",9);
        RANDOMIZE();
        ADD("BlockList",10);
    }}
End Unverified


Got 4 Groups, all should be contain same amount of participants.
Maybe I forgot
my$VALUE or something like that?
Ok, so now create a quota question called QUOTAGROUP.

Define 4 quota cells called Block 1-4. Set their targets to the same amount.

Select least fill as the membership type.

Insert this question before the block questions.

Now you should have it working nicely.
Thanks! It works perfect.
Just to know - now the decision in which group the respondent comes isn't randomized it's obviously always this group with least fills.

Are there opportunities to randomize this as well?

Edit: sometimes more groups came in a row... so i have to change second and third if-construction to elsif - right?
You can change the quota cell membership to randomise to change least fill to random selection.

And you can change the number of blocks in both the quota question and constructed list to meet your needs.
What about elsif, isn't it right?

And how can I randomise with cell membership?
If you are still using a quota question with your block selection, you can change to randomise where you selected least fill i=within the quota question. It is one of the options in the drop down list.

You can also use block selection without quota questions too and just apply a constructed list with your required logic / script.
i try the first one. second would not make sense, because i just inserted quotas on your recommendation to get same amount of respondents.
If I delete them, it doesn't help ...
Both these solutions come in handy depending on what you are trying to do.

If you need least fill, then certainly using the quota question is required.

If you only need a randomise approach, you can do without the quota question and just use a constructed list and randomise within there.
And if I want to reach both?
A randomisation of groups but in the end every group should have same amount of participants
There are solutions where your can use constructed lists to apply a combination of least fill and randomisation. So when counts are equal randomly select an option.

I can check with the Sawtooth Software team if a randomisation occurs within the least full quota question when counts are equal. I believe it does work that way.

Over many years I’ve dealt with many different block selection criteria and found the constructed lists and/or quota questions handle the task very well.
Thanks for your fast answer. I believe also that would be the way to go.

Another short question:
I got a Question named CVHI it is a select question with two answers
1: Yes and 2: No

Now next question should adapt his text if yes or no is selected.
My idea was to try it this way:

Begin Unverified Perl
    my$CVHI=GETVALUE("CVHI");
if ($CVHI=="Yes")
    {
        return "Text if yes";
else
    {
        return "Text if no"; 
    }
End Unverified %]


but this code does not work, any edits necessary?
Use ==1 instead.

And best to use a different variable name if a question already uses the same name.

You can also remove the my command and just say if GETVALUE(“CVTI”).

So change my $CVHI to my $QCVHI or some other appropriate name.
I have tried this, but it does not work.

[% Begin Unverified Perl
if GETVALUE("CVHI"==1)
{
    return "Text if yes";
}
else
{
    return "Text if no";
}
End Unverified %]
I got it. It is working - however i just looked at preview from 2-3 questions before, because i don't want to click through the whole survey - but preview always shows text if no, in total it works.
Insert an opening bracket before GETVALUE and a closing bracket before ==1.

See below ...
[% Begin Unverified Perl
if (GETVALUE("CVHI")==1)
{
    return "Text if yes";
}
else
{
    return "Text if no";
}
End Unverified %]

Ignore the preview mode for Perl script as it will show the ELSE condition script. Ensure you test it out.
...