First, how can I select one random respondent from eligible respondents from household members?
I have variable hhsize for household size. I have the roster wherein only household members who answered yes in question number 4 will be eligible.
Second, how can I flash the name of this household member in the next static text? I have question number 1 in the roster as the name of household member.
Thank you very much!
Thank you for the response. I’m sorry but this is still unclear to me. For the first link,
“ml.Select(x=>x.Item2).ToArray([(long)Math.Floor(Quest.IRnd()*ml.Count())]” what does the Item2 stand for? Can I substitute an equation, say x.q4==1 instead of x.Item2? How do I do it if my q4 is a question under a roster?
For the second link, with this example: “members.Where(x=>x.age>15 && x.sex==2).Select(x=>x.@rowcode).ToArray()”, do I just add ([(long)Math.Floor(Quest.IRnd()*members.Count())] to select one respondent?
Thank you very much.
No Item1 and Item2 are two standard names for the two parts of a tuple and can’t be substituted with a user-given content
No, the number of eligible respondents is in general smaller than the number of household members, so you risk an “array index out of range” error. You need to count the eligible respondents first:
nEligible=members.Count(x=>x.age>15 && x.sex==2)
Multiplying it by a random value will give you a valid index within an array of eligible respondents.