Reply To: Matching Participants on Race/Gender?

PennController for IBEX Forums Support Matching Participants on Race/Gender? Reply To: Matching Participants on Race/Gender?

#5569
Jeremy
Keymaster

Hello Callie,

All the trials are generated at the very beginning of the experiment, along with the trial sequence, so you will not be able to dynamically select which trials to run the way you are trying to do here.

What I can suggest is a two-step design; it’s not ideal but it works well. The idea is to re-open the experiment after you participants have filled the initial form, but this time with the values they typed as parameters in the URL.

I will be assuming a table with a column race and a column sex that list the values in your experiment. For the sake of illustration, I used this command:

AddTable("practicedatasource.csv", `item,race,sex,sentence
1,Black or African American,Female,Sentence 1 for Black or African American Female
1,Asian or Pacific Islander,Female,Sentence 1 for Asian or Pacific Islander Female
1,Hispanic or Latinx,Female,Sentence 1 for Hispanic or Latinx Female
1,Other,Female,Sentence 1 for Other Female
1,Black or African American,Male,Sentence 1 for Black or African American Male
1,Asian or Pacific Islander,Male,Sentence 1 for Asian or Pacific Islander Male
1,Hispanic or Latinx,Male,Sentence 1 for Hispanic or Latinx Male
1,Other,Male,Sentence 1 for Other Male
2,Black or African American,Female,Sentence 2 for Black or African American Female
2,Asian or Pacific Islander,Female,Sentence 2 for Asian or Pacific Islander Female
2,Hispanic or Latinx,Female,Sentence 2 for Hispanic or Latinx Female
2,Other,Female,Sentence 2 for Other Female
2,Black or African American,Male,Sentence 2 for Black or African American Male
2,Asian or Pacific Islander,Male,Sentence 2 for Asian or Pacific Islander Male
2,Hispanic or Latinx,Male,Sentence 2 for Hispanic or Latinx Male
2,Other,Male,Sentence 2 for Other Male`)

Then you need to define your welcome-screen-form trial to run just in case the URL does not provide you with the demographic information:

if (!GetURLParameter("id")||!GetURLParameter("race")||!GetURLParameter("sex")){
    
    newTrial("ParticipantID",
        defaultText.center(),defaultDropDown.center()
        ,
        newText("<p>Welcome and thank you for helping us!</p>").print()
        ,
        newText("<p>Please select your race and sex. Then, please enter your ID in the box below. "+
                "You can find your ID XXX, and then press enter.</p>")
            .print()
        ,
        newDropDown("race", "Please select the race that best describes you.")
            .add("Black or African American", "Asian or Pacific Islander", "White", "Hispanic or Latinx", "Other")
            .print()
            .wait()
        ,
        newDropDown("sex", "Please select the sex that best describes you.")
            .add("Female", "Male")
            .print()
            .wait()
        ,
        newTextInput("inputID").center().print().wait()
        ,
        newFunction( ()=>window.open("server.py?"+
            "race="+getDropDown("race").value+"&"+
            "sex="+getDropDown("sex").value+"&"+
            "id="+getTextInput("inputID").value
        ) ).call()
    )
    
    SendResults()
    
    newTrial("end", newText("Another window opened, you can now close this one.").print() , newButton().wait() )
    
}

And then define the experimental trials to run upon opening the experiment’s page with the values passed as URL parameters:

if (GetURLParameter("id") && GetURLParameter("race") && GetURLParameter("sex")){
    
    race = decodeURI(GetURLParameter("race"))
    sex = decodeURI(GetURLParameter("sex"))
    
    Sequence("practicesequence","etc")
    
    Template(
        GetTable("practicedatasource.csv")
            .filter("race", race)
            .filter("sex", sex)
        ,
        row => newTrial( "practicesequence" ,
            newText(row.sentence).print()
            ,
            newButton("Next").print().wait()
        )
        .log( "ID" , GetURLParameter("id") )
        .log( "race" , race )
        .log( "sex" , sex )
    )
    
}

Feel free to create two separate script files for each of these to keep your code cleaner

Jeremy