# Assigning participants to random sets

**URL:** <https://discourse.psychopy.org/t/assigning-participants-to-random-sets/20219>\
**Category:** Builder\
**Created:** [February 5, 2021, 4:40am UTC](https://discourse.psychopy.org/t/assigning-participants-to-random-sets/20219 "2021-02-05T04:40:28Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![rita](https://avatars.discourse-cdn.com/v4/letter/r/58956e/32.png) [@rita](https://discourse.psychopy.org/u/rita)\
**Post date:** [February 5, 2021, 4:40am UTC](https://discourse.psychopy.org/t/assigning-participants-to-random-sets/20219/1 "2021-02-05T04:40:28Z")

</div>

If this template helps then use it. If not then just delete and start from scratch.

**OS** (e.g. Win10): Windows 10  
**PsychoPy version** (e.g. 1.84.x): 3  
**Standard Standalone? (y/n)** If not then what?:Y  
\*\*What are you trying to achieve?:\*\*Assigning participants randomly to one of three groups

**What did you try to make it work?:**  
I’m trying to assign participants randomly to 1 of 3 groups to read a word list. I have 3 sets of word files (OrderA, OrderB, and OrderC) in three excel files.

 ![builder routine](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/f/0/f08a5b9c5bcec7fa213a7a002f7b0409504b50c9.jpeg)  
Under assigncond routine I have added the following code in ‘begin experiment’:  
import random  
condition = random.choice((‘OrderA.xlsx’or’OrderB.xlsx’or’OrderC.xlsx’))

**What specifically went wrong when you tried that?:**  
Include pasted full error message if possible. “That didn’t work” is not enough information.

When I loop each condition individually, all three lists are displayed. I read from another post that a single loop can be used- although I don’t know what should be included under the conditions field in the loop. I am new to PsychoPy. Would really appreciate any help on this.

Rita

---

<div class="post-metadata">

**Author:** ![JensBoelte](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/jensboelte/32/9060_2.png) [@JensBoelte](https://discourse.psychopy.org/u/JensBoelte)\
**Post date:** [February 5, 2021, 11:29am UTC](https://discourse.psychopy.org/t/assigning-participants-to-random-sets/20219/2 "2021-02-05T11:29:17Z")

</div>

Dear rita

I attach three dummy condition-files and a toy-psyexp for illustration.

[conditiongroup1.xlsx](https://discourse.psychopy.org/uploads/short-url/xxthDbD0RZ6GCdIYdS1mYzeHI7F.xlsx) (8.4 KB) [conditiongroup2.xlsx](https://discourse.psychopy.org/uploads/short-url/jIfpdgrsVvl1srsVtVC4AKB9Pxp.xlsx) (8.4 KB) [conditiongroup3.xlsx](https://discourse.psychopy.org/uploads/short-url/lkIJDc59DW8mIAAz3GWCxLgFxTE.xlsx) (8.4 KB) [Demo.psyexp](https://discourse.psychopy.org/uploads/short-url/wFJ9dPqN36tEl0F8VQY9UmO6Mmj.psyexp) (7.2 KB)

In the first routine of your experiment before you access any condition-file insert a code-component.

```auto
conditionFile = " "

if int(expInfo['participant'])%3 == 0:
    conditionFile = "conditiongroup3.xlsx"
elif int(expInfo['participant'])%2 == 0:
    conditionFile = "conditiongroup2.xlsx"
else:
    conditionFile = "conditiongroup1.xlsx"

```

Then in the loop refer to the particular condition file by **$conditionFile** in the Conditions field of the loop. Do not forget to add the three Excelfiles to **Additional Resources** ( **Experiment**  **Settings** - **Online** ) if you want to run the experiment online. I used the participant id to assign the different files but you could use any other information that you define in the Experiment info.

Best wishes Jens

---

<div class="post-metadata">

**Author:** ![rita](https://avatars.discourse-cdn.com/v4/letter/r/58956e/32.png) [@rita](https://discourse.psychopy.org/u/rita)\
**Post date:** [February 5, 2021, 1:58pm UTC](https://discourse.psychopy.org/t/assigning-participants-to-random-sets/20219/3 "2021-02-05T13:58:35Z")

</div>

Dear Jens,  
Perfect!  
Thank you so much!  
If I want to do a second trial, again assigning participants randomly to any three different conditions, I will just need to change the names of the file in the code in another start routine?  
And upload the files in settings?

Rita

---

<div class="post-metadata">

**Author:** ![JensBoelte](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/jensboelte/32/9060_2.png) [@JensBoelte](https://discourse.psychopy.org/u/JensBoelte)\
**Post date:** [February 5, 2021, 2:58pm UTC](https://discourse.psychopy.org/t/assigning-participants-to-random-sets/20219/4 "2021-02-05T14:58:05Z")

</div>

Dear Rita,

what do you mean by second trial? At the moment, I would describe the experiment as having three trials while each participant sees from one of three conditions (there are three 1s in conditiongroup1, three 2s in conditiongroup2 aso.) based on the participant number.

It is best to describe the experiment as you would describe it in the Method section of your manuscript. In this way others can follow 😉

Best wishes Jens

---

<div class="post-metadata">

**Author:** ![rita](https://avatars.discourse-cdn.com/v4/letter/r/58956e/32.png) [@rita](https://discourse.psychopy.org/u/rita)\
**Post date:** [February 6, 2021, 1:21am UTC](https://discourse.psychopy.org/t/assigning-participants-to-random-sets/20219/5 "2021-02-06T01:21:18Z")

</div>

Hi Jens,  
Thanks again for your reply. This is what I want to design:  
welcome → practice memory list → practice recognition → test cond1/2/3 memory list → recognition1 → test cond 4/5/6 → recognition2.

Just like the demo you did for me for the first stage random assignment (cond1/2/3), I want to do a second block assigning the same participant again to one of three different conditions 4/5/6 with different word lists.  
1.Would it be a problem to do a practice run before the random assignment (cond1/2/3)?  
2. How do I assign the participant again in the second round for cond 4/5/6? Is it the same as cond1/2/3 with changes in the code and uploading the files in settings?

---

<div class="post-metadata">

**Author:** ![JensBoelte](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/jensboelte/32/9060_2.png) [@JensBoelte](https://discourse.psychopy.org/u/JensBoelte)\
**Post date:** [February 6, 2021, 2:01pm UTC](https://discourse.psychopy.org/t/assigning-participants-to-random-sets/20219/6 "2021-02-06T14:01:18Z")

</div>

Hello Rita,

ad 1) no not at all, either you use a different list aka Excelfile for practice or use the **selected row** property of the **loop** to select specific rows from your Excelfile as practice trials and other as the experimental trials. I would probably go for the first solution.

ad 2) you could use the same code for condition1/2/3 to assign participants to condition 4/5/6. I suggest to start with a toy-example, not your real material. Simply create three more Excelfiles containing 4/5/6, assign them to participants with some code as you did before 😉 and add the files as additional resources.

Do you want to combine everything with everything? Or do you want to present only specific combinations?

Best wishes Jens

---

<div class="post-metadata">

**Author:** ![rita](https://avatars.discourse-cdn.com/v4/letter/r/58956e/32.png) [@rita](https://discourse.psychopy.org/u/rita)\
**Post date:** [February 8, 2021, 12:50pm UTC](https://discourse.psychopy.org/t/assigning-participants-to-random-sets/20219/7 "2021-02-08T12:50:26Z")

</div>

Hello Jens,

Both the practice and second test worked, just like the first one I designed 😉  
I could not do it using another 3 Excel files (4/5/6). It seems to pick up the same conditiongroup for test 1 and again in test 2 (e.g conditiongroup4 in test 1 and again in Test 2), although I added all files to Resources. So I combined the list and selected rows. I am not looking for specific combinations- so it works fine.  
Thanks again! 😀  
Best wishes,  
Rita

---

<div class="post-metadata">

**Author:** ![JensBoelte](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/jensboelte/32/9060_2.png) [@JensBoelte](https://discourse.psychopy.org/u/JensBoelte)\
**Post date:** [February 9, 2021, 9:06am UTC](https://discourse.psychopy.org/t/assigning-participants-to-random-sets/20219/8 "2021-02-09T09:06:52Z")

</div>

Hello Rita

do mind showing how you tried to achieve this? Keep in mind that you need another variable to store the condition-file.

Best wishes Jens

---

<div class="post-metadata">

**Author:** ![rita](https://avatars.discourse-cdn.com/v4/letter/r/58956e/32.png) [@rita](https://discourse.psychopy.org/u/rita)\
**Post date:** [February 9, 2021, 2:55pm UTC](https://discourse.psychopy.org/t/assigning-participants-to-random-sets/20219/9 "2021-02-09T14:55:41Z")

</div>

Hello Jens

What do you mean by another variable to store the condition-file?

 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/6/f/6ffaab3a118179619866a1b71821866588dd32e1.png)

I did the same thing for test 1 and 2 by using the same code (just changing conditiongroup name to 4, 5,6), and uploading the extra files in additional resources.  
Now I have combined wordlist from (e.g conditiongroup1 and 4) and selected rows for test 1 and test 2 -Excel sheet attached.

I’m also trying to provide feedback for the practice recall and have some problem here.  
I have stored correct answer and my excel file is like the one attached but it does not work.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/6/5/65cc3b64cba38144a4684801e5102096448bf09d.png) [response.xlsx](https://discourse.psychopy.org/uploads/short-url/rupPPvUrVWniZ0PsP6MXo7hhrSd.xlsx) (8.5 KB) [two methods.xlsx](https://discourse.psychopy.org/uploads/short-url/tSuViJ9lhabOaoC86B4apA0kEyl.xlsx) (9.7 KB)

Best wishes,  
Rita

---

<div class="post-metadata">

**Author:** ![JensBoelte](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/jensboelte/32/9060_2.png) [@JensBoelte](https://discourse.psychopy.org/u/JensBoelte)\
**Post date:** [February 9, 2021, 4:53pm UTC](https://discourse.psychopy.org/t/assigning-participants-to-random-sets/20219/10 "2021-02-09T16:53:27Z")

</div>

Hello Rita

you need to store the value of the condition-file for the second block in a variable (e.g. conditionBlock2) different from the variable (e.e.g conditionBlock1) in the first block. conditionBlockN go into the respective loop. But given that selected rows worked for you and you don’t need complete randomization of all condition-files, I guess you are fine.

Best wishes Jens

---

<div class="post-metadata">

**Author:** ![rita](https://avatars.discourse-cdn.com/v4/letter/r/58956e/32.png) [@rita](https://discourse.psychopy.org/u/rita)\
**Post date:** [February 10, 2021, 1:30am UTC](https://discourse.psychopy.org/t/assigning-participants-to-random-sets/20219/11 "2021-02-10T01:30:37Z")

</div>

Hello Jens,  
That makes sense! Thanks for explaining. Its good to know a few different ways of doing this.

Do you have any idea on the response feedback I mentioned in the post above?

Best wishes,  
Rita

---

<div class="post-metadata">

**Author:** ![JensBoelte](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/jensboelte/32/9060_2.png) [@JensBoelte](https://discourse.psychopy.org/u/JensBoelte)\
**Post date:** [February 11, 2021, 11:24am UTC](https://discourse.psychopy.org/t/assigning-participants-to-random-sets/20219/12 "2021-02-11T11:24:08Z")

</div>

Dear Rita

here some code I use to provide feedback:

```auto
if resp.corr:
    msg = "richtig RT = %.3f" %(resp.rt)
    msgColor = "green"
else:
    msg = "falsch RT = %.3f" %(resp.rt)
    msgColor = "red"

```

Note that this does not autotranslate to proper PsychoJS. You have to code this manually and set the code-component to both:

```auto
if (resp.corr) {
    msg = "richtig RT =" + resp.rt.toFixed(3) + " sec.";
    msgColor = "green";
} else {
    msg = "falsch RT =" + resp.rt.toFixed(3) + " sec.";
    msgColor = "red";
}

```

**resp** is the name of the keyboard-component and registered in the routine preceding the feedback-routine. There is a variable named **correct** that refers to the column **correct** in an Excel-file which contains the correct key to be pressed.

 ![grafik](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/f/c/fcc1cf8834a198e64bd192fb0469669976cbebf4.png)

![grafik](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/6/7/6773518295c275dd11f160767e89ebfacb63dcd5.png)

**msg** is the variable that holds the feedback-message. The code-component determining the feedback must occur above the feedback text-component (see below, ignore the element tastenText. This is special to this experiment.).

 ![grafik](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/d/3/d39bdb78f3963787227810bf1a337604aa6959a9.png)

 ![grafik](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/5/3/53a4fc9bada84fed85e4e53384fa4bc6d4cc2771.png)

Best wishes Jens

---

<div class="post-metadata">

**Author:** ![rita](https://avatars.discourse-cdn.com/v4/letter/r/58956e/32.png) [@rita](https://discourse.psychopy.org/u/rita)\
**Post date:** [February 11, 2021, 11:43am UTC](https://discourse.psychopy.org/t/assigning-participants-to-random-sets/20219/13 "2021-02-11T11:43:21Z")

</div>

Hello Jens  
There was a minor error in my code. Fixed now!  
Thank you!

Best wishes,  
Rita

---

<div class="post-metadata">

**Author:** ![Mina](https://avatars.discourse-cdn.com/v4/letter/m/839c29/32.png) [@Mina](https://discourse.psychopy.org/u/Mina)\
**Post date:** [July 19, 2022, 9:23am UTC](https://discourse.psychopy.org/t/assigning-participants-to-random-sets/20219/14 "2022-07-19T09:23:35Z")

</div>

Lieber Jens,

I also tried to follow your dummy-demo (thanks for that!), although it’s doesn’t work for me despite implementing all the steps. When running online, it says that my pendant to your “group” parameter is not defined, although I checked like 2516 times and everything should be consistent. Any tipps?

Thank you very much in advance!  
Liebe Grüße  
Mina
