For the survey instrument I am designing, I need to select the minimum value in two different situation:
- from a categorical: multi-select variable.
e.g. Where did you seek treatment from: answers are (2) Public hospital, (5) Private clinic and (9) Pharmacy. For following questions, I will ask only about the answer with lowest code, here Public hospital.
- from a roster.
e.g. my education roster has two cases corresponding to two kids: Kid 1 has achieved Grade 5 and Kid 2 has achieved 3. I want to ask questions (out of the roster) about the kid with lowest level of education.
Any idea on how I could achieve these? I have seen the function MIN on C# but not sure on how to use it, and on whether it works for a multi-select and/or within a roster.
Thanks a lot!
Benjamin, you are absolutely right about the use of the Min() function.
For the first question – the expression mcq.Yes.Min() will give you the value of the lowest selected option (2 in your example) regardless of the order of options.
For the second question, please describe how you want to break the ties (example: of 10 kids, the lowest grade was achieved by 3).
I used mcq to denote Multiple Choice Question the name of which was not specified in your original query. You need to write the actual variable name (Q3_5) instead of “mcq”.
The method you ended up using works, but may create unnecessary complexity as it creates a new level of data. In many cases this is not required. The rule of thumb is that the roster’s purpose is to replicate questions for N items. If you know there will always be N=1, there is no need for a roster. You don’t have to assign the expression to a variable, but it may improve readability of some expressions.
For the second question you wrote “ask more about one kid only, the one with the lowest level of education” but you still haven’t specified what do you want to do in case children Arnold, Berta and Charlie each have grade 3 completed. You specified that you want to talk to 1 kid only. Which one? Youngest? oldest? listed first? random? alphabetical?
the answer to #1 is here:
the answer to #2 is here:
what you can do is take @rowcode instead of the @rowname. This will be the code of the person in question. Call this variable PERSCODE.
then create another variable PERSNAME retrieving the person’s name by code from the original household members list question. The list question is a TUPLE structure in C#, see the link in the data types page:
Then you can substitute PERSNAME in the question text.
This question has received the maximum number of answers.