Children randomization

3 years 2 months ago #183760 by vipgroup
Dear friends, I have one question about randomisation possibility. My survey contains a question about age of all children in the family aged 0-18 years-
q1 - How old are your children?
q1_1. Child 1 ___ years old
q1_2. Child 2 ___ years old
q1_n...
q1_9. Child 9 ___ years old
For instance, there are 5 children in a family aged 1, 5, 7, 10, 15 years old. The youngest children (1 and 5) are not valid for randomisation, so I need randomly select one of 7, 10 and 15 year old child and ask about this child additional question. And then I need to understand in the data file about which selected child all additional questions were asked.
I tried to use (rand(min,max)), but I can't know max number of children in each family. I can use count(that.q1.NAOK) to get number of childen, but I can't understand how can I use rand(min,max) to random aged >7 children.
Any ideas how to do it?

Thanks a lot,
The topic has been locked.
3 years 1 month ago #183778 by Joffm
Replied by Joffm on topic Children randomization
Hi, there are several solutions.
I prefer this:
create a question of type equation (eqQ0) with this:
{substr( join(if(Q0_SQ001.NAOK>7,"A",""),if(Q0_SQ002.NAOK>7,"B",""),if(Q0_SQ003.NAOK>7,"C",""),if(Q0_SQ004.NAOK>7,"D",""),if(Q0_SQ005.NAOK>7,"E","")),rand(1,countifop(">",7,that.Q0.NAOK))-1,1)}
which will give you a letter "A" - child 1, "B" - child 2,...
If you provide less then 10 options you may use digits instead.

Now what does this equation do?
with the join function you build a string that contains only the children >7
join(if(Q0_SQ001.NAOK>7,"A",""),if(Q0_SQ002.NAOK>7,"B",""),if(Q0_SQ003.NAOK>7,"C",""),if(Q0_SQ004.NAOK>7,"D",""),if(Q0_SQ005.NAOK>7,"E",""))
you create a random number between 1 and the number of children>1
rand(1,numChildren)
The number of children you get by the countifop function ("<",7,Q0), count Q0, if <7
At last you extract the letter from your string that refers to your random number.
Remember: substr starts counting with 0.

Here you can display the number of the child by micro-tayloring.
"Now we talk about child {if(eqQ0=="A","Child 1",if(eqQ0=="B","Child 2",if(eqQ0=="C","Child 3",if(eqQ0=="D","Child 4","Child 5"))))}
If you have you can enter the name of the child or whatever.

So you will get a very short survey. Only one group for your additional questions.
And in the dataset you'll habe the letter to distinguish between the children.

And additionally you have to check if there are children>7

Joffm

File Attachment:

File Name: limesurvey...1335.lss
File Size:19 KB

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Attachments:
The following user(s) said Thank You: DenisChenu, holch, vipgroup, cdorin
The topic has been locked.
3 years 1 month ago #183836 by vipgroup
Replied by vipgroup on topic Children randomization
Dear Joffm, you are genius! Everything works perfectly, I will test it a little bit later with 10 children, but it seems now, that the randomization works good! I could not write the equation with out your help.
Thanks you so much for your help, Joffm
Best wishes to you from Riga,
Andrew
The topic has been locked.
3 years 1 month ago #183932 by vipgroup
Replied by vipgroup on topic Children randomization
Dear Joffm,
Thanks you again for your help! I tried your example, it works well, but I would like to clarify one thing how to do -

The script, provided by you, selects one child. However after filling in the question about the randomly selected child (gender in your example), the selected child is being changing. For instance, the 10 y.o child was selected in the question eqQ0 and the next gender question was asked about this child, but when I mark the gender, the child in eqQ0 is being changing again.
Here is an example of your survey - www.webresearch.lv/index.php/481335?newtest=Y&lang=en
In addition, the child, selected in the question eqQ0, is not the same, about who is being asked next questions. Is it possible to avoid this inconsistency?

I have attached your updated script, may be you have any idea how to avoid child's changing during the questionnaire?

Thank you very much in advance!
BR, Andrew
The topic has been locked.
3 years 1 month ago #183937 by Joffm
Replied by Joffm on topic Children randomization
Hi,
I used the method "question by question".
If you use "group by group" you should set the equation into a separate group.
But if you do it "all on one page" you have to split the equation.

Reason: Each time the page that contains the equation is loaded the random number is calculated again.

So you have to calculate the random number separately by the well known way:
{if(!is_empty(random),random,rand(1,X))}

So here a example (hide the equation question in the active survey)

File Attachment:

File Name: limesurvey...4-30.lss
File Size:22 KB

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Attachments:
The following user(s) said Thank You: vipgroup
The topic has been locked.
3 years 1 month ago #184241 by vipgroup
Replied by vipgroup on topic Children randomization
Dear Joffm,

Thank you so much for your help! I could not do it by my self without you.
I have to re ask you once again. The script provided by you works well, but now the randomization in the question eqQ0b chooses only the first valid child. For instance, if the age of 5 children is 1-5-10-15-18, the script correctly identify for randomization valid children – 10-15-18 years old, but all the time it choose the first child - 10 years old in my example.
Joffm, I highly appreciate your help, but may be you can help once again with example provided by you? How to correct the randomization to choose valid children randomly?

Andrejs
Attachments:
The topic has been locked.
3 years 1 month ago #184243 by Joffm
Replied by Joffm on topic Children randomization
Hi,
well that's obvious.
You cannot do it "all on one page".

What happens?
After you enter the first child >7 the randomization is rendered. Of course this - the only one - child is chosen.
Afterwards because we use the statement " if( ! is_empty(eqQ0b), eqQ0b, rand(1, count...)) this random number is not changed.
If you just enter "rand(1,count...) the random number will be changed every time the page is rendered, after each answer to one of the questions.
That you realized before.

Therefore my first example was for "question by question" and the second "group by group".

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.