Hi I am doing a conjoint experiment on Qualtrics using the following code. The questions asks respondents to choose between two political candidates based on their attributes. These attributes are randomly selected. I want to analyse what respondents choose between the two options especially for the policy option. However, I am running into issues with the code every time I run it. I will love to have some feedback on this code!
// seed random number generator from embedded data fields
// conjoint profile 1
//Math.seedrandom('${e://Field/seed1}');
// conjoint profile 2
//Math.seedrandom('${e://Field/seed2}');
// conjoint profile 3
//Math.seedrandom('${e://Field/seed3}');
// conjoint profile 4
//Math.seedrandom('${e://Field/seed4}');
// conjoint profile 5
//Math.seedrandom('${e://Field/seed5}');
// seed random number generator from embedded data fields
// conjoint profile 1
Math.seedrandom('${e://Field/seed1a}' * '${e://Field/seed1b}');
Math.seedrandom('${e://Field/seed1}');
// conjoint profile 2
//Math.seedrandom('${e://Field/seed2a}' * '${e://Field/seed2b}');
//Math.seedrandom('${e://Field/seed2}');
// conjoint profile 3
//Math.seedrandom('${e://Field/seed3a}' * '${e://Field/seed3b}');
//Math.seedrandom('${e://Field/seed3}');
// conjoint profile 4
//Math.seedrandom('${e://Field/seed4a}' * '${e://Field/seed4b}');
//Math.seedrandom('${e://Field/seed4}');
// conjoint profile 5
//Math.seedrandom('${e://Field/seed5a}' * '${e://Field/seed5b}');
//Math.seedrandom('${e://Field/seed5}');
This is where I define dimensions
//Define the dimensions
var attRaw=["sex", "ethnicity", "family", "experience", "status", "policy"];
var att=["sex", "ethnicity", "family", "experience", "status", "policy"];
var attributes=["", "", "", "", "", ""];
// Create Variables for Traits associated with each dimension.
var sex_raw = ["Male", "Female"];
var ethnicity_raw=["American Indian", "White", "Asian", "Black", "Latino"];
var family_raw= ["Belongs to a political family", "Does not belong to a political family"];
var experience_raw = ["Inexperienced", "Experience of 1 to 3 years", "Experience of 3 to 5 years"];
var status_raw = ["Incumbent", "Non-incumbent"];
var policy_raw=["Agriculture", "Education", "Roads and Infrastructure"];
Again, this is where I randomise the order
//randomize order of dimensions
for (i=0, i<attRaw.length, i++){
var rand1=Math.floor(Math.random()*((attRaw.length-i-)0));
attributes[i]=att[rand1];
att.splice (rand1, 1);
}
I use the following function to randomize race
// Functions for setting race and religion approximately proportionately
function getEthnicity(){
// 20% American Indian, 20% White, 20% Asian, 20% Black, 20% Latino
var n = Math.floor(Math.random()*100);
if (n<20) {
var out = 4;
} else if (n <40) {
var out = 3;
} else if (n<60) {
var out = 2;
} else if (n< 80) {
var out=1;
} else {
var out = 0;
}
var ethnicity_raw = ["American Indian", "White", "Asian", "Black", "Latino"];
return ethnicity[out];
}
Next I choose the attributes for candidate A
// Use math.random to randomly select traits for each dimension for candidate A
var sex_a = sex_raw[Math.floor(Math.random()*sex_raw.length)];
var ethnicity_a= getEthnicity();
var family_a= family_raw[Math.floor(Math.random()*family_raw.length)];
var status_a= status_raw[Math.floor(Math.random()*status_raw.length)];
var experience_a=experience_raw [Math.floor(Math.random()*experience_raw.length)];
var policy_a=policy_raw[Math.floor(Math.random()*policy_raw.length)];
Next for candidate B
// Use math.random to randomly select traits for each dimension for candidate B
var sex_b = sex_raw[Math.floor(Math.random()*sex_raw.length)];
var ethnicity_b= getEthnicity();
var family_b= family_raw[Math.floor(Math.random()*family_raw.length)];
var status_b= status_raw[Math.floor(Math.random()*status_raw.length)];
var experience_b=experience_raw [Math.floor(Math.random()*experience_raw.length)];
var policy_b=policy_raw[Math.floor(Math.random()*policy_raw.length)];
Indexing it
//order of dimension variable
var sex_index = attributes.indexOf("sex");
var ethnicity_index=attributes.indexOf("ethnicity");
var family_index=attributes.indexOf("family");
var status_index=attributes.indexOf("status");
var experience_index=attributes.indexOf("experience");
var policy_index=attributes.indexOf("policy");
//now place the attribute in the right order for candidate a
att_a_traits[sex_index]=race_a;
att_a_traits[ethnicity_index]=ethnicity_a;
att_a_traits[family_index]=family_a;
att_a_traits[status_index]=status_a;
att_a_traits[experience_index]=experience_a;
att_a_traits[policy_index]=policy_a;
//doing the same for b
att_b_traits[sex_index]=race_b;
att_b_traits[ethnicity_index]=ethnicity_b;
att_b_traits[family_index]=family_b;
att_b_traits[status_index]=status_b;
att_b_traits[experience_index]=experience_b;
att_b_traits[policy_index]=policy_b;
This is where I map it to HTML
// Create list of variables to use when setting attributes
att_list=["att1", "att2", "att3", "att4", "att5", "att6"];
a_list = ["a1","a2","a3","a4","a5","a6"];
b_list = ["b1","b2","b3","b4","b5","b6"];
// set html values in conjoint table
for(i=0;i<7;i++){
document.getElementById(att_list[i]).innerHTML=traits_att[i];
document.getElementById(a_list[i]).innerHTML = att_a_traits_a[i];
document.getElementById(b_list[i]).innerHTML = att_b_traits_b[i];
}
Unfortunately, this code doesn't work and I have different variations but it does not even show the options. Any clue on what could be wrong?