Have an idea?

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

Maxdiff on the fly rank ordering

I'm trying to get the maxdiff on the fly rank order of a specific item that’s somewhere in the middle of the list. E.g. the rank order of item #16 or #27 only from a list of 50 items.
We wrote a custom code that would generate the output but for some reason I could not make it work. Is there who could help on what I getting wrong (see snippet of the code below) or any alternative solution?
thanks

[Code]

[%Begin Unverified Perl

my $Q1_string="0";
my $userIda1 = LISTLABEL("MDOTF1",1);
my $userIda2 = LISTLABEL("MDOTF1",2);
my $userIda3 = LISTLABEL("MDOTF1",3);
if ($userIda1 == 27)
{
  $Q1_string="1";
}

elsif ($userIda2 == 27)
 {
  $Q1_string="2";
 }

elsif ($userIda3 == 27)
 {
  $Q1_string="3";
 }


return $Q1_string;

End Unverified%]
asked Nov 23 by anonymous
MDOTF1 is a non-constructed list with items defined like below, I assume?

1. [% MaxDiffRankAttValue(___, 1) %]
2. [% MaxDiffRankAttValue(___, 2) %]
3. [% MaxDiffRankAttValue(___, 3) %]
...


Your code could be shortened with a loop, but it seems like it should work if that is the case.  What problem are you seeing with this code?
Yes, MDOTF1 is the list. The code runs without error but it doesn't return the rank order of the specified items, #27 in this case.
I don't know why that would be.  Could you share your study with our support team so I can take a deeper look?
Hi Zackary,

Do you mean the Sawtooth support team (support@sawtoothsoftware.com) because we already sent them the study yesterday or is it a different email address?

I also can share it again.
I see.  It seems like you may have attached the incorrect file to your email.  Did you mean to send your .ssi file?

1 Answer

0 votes
Your list needs to use the MaxDiffRankAttValue function, not MaxDiffRankAttLabel.

Your script should work then, but I would still recommend you replace it with this for simplicity:

[% Begin Unverified Perl
for (my $i = 1; $i <= 50; $i++) {
    if (LISTLABEL('MDOTF1', $i) == 27) {
        return $i;
    }
}
End Unverified %]
answered Nov 24 by Zachary Platinum Sawtooth Software, Inc. (188,900 points)
This works, thank you. The only other issue we have is that we included a URL in the Terminate page that is supposed to redirect to another questionnaire but for some reason our code doesn't work nor do we get the URL output when we run the  terminate screen of the study.
Just to clarify, we would like to export that value from the Perl code into our URL link. Would we create a variable in the Perl code that would then get inserted into the URl link such as variable'Q1_27'?
Placing this script into the URL ought to work.

http://example.com?value=[% Begin Unverified Perl ... End Unverified %]


Using a variable would keep us from having to do the same work twice, though.  You could add a pass-in variable to your survey and add this line of code between lines 3 and 4:

SETVALUE('PassInField', $i);


("PassInField" being the name of your variable, naturally.)

Then you could use that variable in your URL:

http://example.com?value=[% PassInField %]
...