Randomly select a name from age group (under 5, 5-15, over 15 )

Hello Forum

Please, I need help, I want to interview members of the household, they will first give their I will list their names and age. Later, I want my ODK form to randomly select a single person (if available) for each age category (under 5, 5-15 and over 15) and display his/her name for further questions. Consider the example below:

A household is occupied by 8 members of different ages. after listing their names and age, now I want my ODK form to select randomly a single member per each age group if they are available on the interviewed list 0-4, 5-15, or over 15 age categories. A total of three people or less who are going to answer further questions by "repeating groups" see the attached Register.xls (26.5 KB)

Hi @godlove

unfortunately it's not possible to do such complicated operations in ODK Collect.

Hi @Grzesiek2010
Thank you for your feedback

You can absolutely do this kind of thing with the ODK form specification! Unfortunately, XLSForm doesn't make that super obvious but you can write XPath expressions within an XLSForm.

This form shows an example that you can hopefully follow to get to your desired behavior. I used XPath syntax where necessary for filtering and XLSForm's compact ${} syntax elsewhere. I hope it's clear enough that you can pattern match without necessarily understanding all the details.

3 Likes

Bugger, @LN bet me to it... but here's my take! :slight_smile:

categories.xls (9.5 KB)

Ha, never under-estimate what cleverness you can put into an XForm, with a bit of creativity... :wink:

[alas, I must rescind your 'solution' @Grzesiek2010 and give it to a well-deserving @LN, but I'm sure you'll earn it back soon enough :grin: ]

4 Likes

That's great, @Xiphware! I decided not to go in that direction because of the space limitation but I think it may be easier to understand. :+1:

Great uses of selected-at function. Thanks for your solution.

Dear @ Xiphware

Thank you for the strong support

Is it possible to count the total number of people who are selected to answer the questions

Best regards

Godlove

Thank you for the strong support

Is it possible to count the total number of people who are selected to answer the questions

Best regards

Godlove

Yes, you can use the count() function which will give you the number of repetitions, ie number of family members.

See https://docs.opendatakit.org/form-repeats/#counting-the-total-number-of-iterations for details.

1 Like

Can you help me to put in this xls as you desingnedcategories.xls (27 KB)

1 Like

Sorry for taking you time my friend!.

Yes sorry, I shouldn't have broken my rule which is answer if you know a solution and wait for other users if you just want to say sorry it's not possible.

1 Like

If the selected respondent has more than one name, how do I make it pick all the names. For example I have a selected reposndent whose name is Randy Shaw. However is giving me only Shaw instead of Randy Shaw. How do I sort this?
Thanks

Xiphware, you very right. I had told someone that over 90% of what you think in an Xform is possible.
Struggled with a code and at the got it to work by just replacing or with and.

Could you attach your form?

Hello everyone,

I have a similar problem to the one discussed here and wanted to get some help to see what I am missing.

How can I make ODK randomly select 40 numbers without replacement between 1 and N, where N is an integer inputted by the user in a previous question.

More specifically, in question 1, we ask for the number of households in the village. Following this question, I would like insert a 'calculation question' that will randomly select 40 numbers without replacement between 1 to N, where N is the total number of households.

Let me know if you have a nice way of doing this.

Thank you in advance for your help and stay safe

Olimpia