Have an idea?

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

Attribute randomization CBC

Dear all,

I'm building a CBC with attribute randomization. (Simply by selecting "Randomize all" in the additional Design settings.

All attributes will be explained to the respondent one page before the choice task. To make the respondent's life easier, we want to show the explanation in the same order as in the Choice task later. Is there a way to do this? I did not find an answer in the lighthouse studio help and  I also could not find the order of attributes in the exported design file so it would be great if I find an answer in this forum.

Thanks and best regards,
Martin
asked Apr 22 by Martin
The CBC-related Sawtooth Script function can be used to get the post-randomization order of attributes.  Try adding this simple example to a text somewhere in your survey:

1st: [% CBCAttributeValue(MyCbc_Random1, 1, 1) %]<br/>
2nd: [% CBCAttributeValue(MyCbc_Random1, 1, 2) %]<br/>
3rd: [% CBCAttributeValue(MyCbc_Random1, 1, 3) %]<br/>


"MyCbc" being the name of the exercise.

I may be able to help in sorting your explanations with this data if you need it.  How are your explanations put on the page?  Rows of a table?  A handful of "<div>" elements?
Dear Zachary,

thank you very much! I can see the correct position of each attribute, now. Some more help, sorting in the explanations would be great. I just use paragraphs:

<p><b>Attribute A</b><br>Description A</p>
<p><b>Attribute B</b><br>Description B</p>
<p><b>Attribute C</b><br>Description C</p>
 


Thanks and greetings from Germany,
Martin

1 Answer

0 votes
 
Best answer
Great, I think we can make this work.  Let's start by wrapping the paragraphs so they all share a parent element like this:

<div id="attributeDescriptionWrapper">
    <p>att 1 text...</p>
    <p>att 2 text...</p>
    <p>att 3 text...</p>
</div>


Then we can add this script to the page to sort the paragraphs for us:

<script>
$(document).ready(function(){
    // Params
    var id = 'attributeDescriptionWrapper';
    var attributeValues = [
        [% CbcAttributeValue(MyCbc_Random1, 1, 1) %],
        [% CbcAttributeValue(MyCbc_Random1, 1, 2) %],
        [% CbcAttributeValue(MyCbc_Random1, 1, 3) %]
    ];
    
    // Run
    var wrapper = $('#' + id);
    var paras = attributeValues.map(function(val){ return $(wrapper).children().eq(val - 1); });
    $(wrapper).append(paras);
})
</script>


Changes can be made to lines 6-8, replacing "MyCbc" with your exercise name and making sure there is one line per attribute.  Notice how there is a comma at the end of each of these lines except the last one.
answered Apr 22 by Zachary Platinum Sawtooth Software, Inc. (171,525 points)
Thank you very much, it works perfect!
...