How to randomly assign a word into the text of a question? | XM Community
Question

How to randomly assign a word into the text of a question?

  • 18 November 2020
  • 1 reply
  • 52 views

Hi All!
For a new project I am asking participants (i.e., Prolific Users) to evaluate five resumes of job applicants (i.e., a deck of resumes programmed as a block). These resumes contain five elements of information, among which is the name of the applicant. The name of the job applicants can be one out of four types: (1) a name of a white woman, (2) a name of a black woman, (3) a name of a white man, (4) a name of a black man. A deck thus consist of five different resumes varying over the type of names presented.
E.g., we ask a participant to evaluate:
(1) a resume of a white woman,
(2) a resume of another white woman,
(3) a resume of a black man,
(4) a resume of a white man,
(5) a resume of a black woman.
The resumes are presented in a tabulated way. For example:
image.png
For each of the type of names we constructed a pool of 10 different names. E.g., regarding the white female names the names are: Susan Smith, Allison Brown, Carrie Jones, etc. Now the idea is to, for each resume, randomly draw (without replacement) one name out of the associated pool of ten names and assign it to the resume. E.g. for the resume of the first white woman we thus want to randomly assign 1 name out of the pool of 10 white female names. For the resume of the second white woman we want to randomly assign 1 name out of the same pool of white female names, while making sure the name of the first white woman is not selected again (i.e., without replacement). Otherwise the same participant is evaluating two different resumes with the same name.
Now, I was wondering how I could program this in Qualtrics?
Thanks in advance,
H


1 reply

Userlevel 4
Badge +4

Create embedded data variables for each resume, e.g. resume_1_white_woman, resume_2_white_woman (and ditto for other combinations of white/non-white man/woman).
Use javascript to set the values of these variables at the beginning. For example:
//defining all white woman names
var all_white_woman_names = ['Susan Smith', 'Allison Brown', 'Carrie Jones']

//pseudo-randomising the list using the below shuffling function
//doing it 5 times to ensure good randomisation
for (s=0; s<5; s++) {
shuffle(all_white_woman_names)
}

//setting the created embedded data values
//where first name in the list (which is now randomized for each PP)
//is assigned to the first embedded data
for (i=0; i Qualtrics.SurveyEngine.setEmbeddedData('resume_'+(i+1).toString()+'_white_woman', all_white_woman_names[i]);
}

function shuffle(array) {
 var currentIndex = array.length, temporaryValue, randomIndex;

 // While there remain elements to shuffle...
 while (0 !== currentIndex) {

// Pick a remaining element...
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;

// And swap it with the current element.
temporaryValue = array[currentIndex];
array[currentIndex] = array[randomIndex];
array[randomIndex] = temporaryValue;
 }

 return array;
}
Then simply use your now set embedded data values in your questions.

Leave a Reply