Random selection based on characteristics

Hi,

Im trying to random select a woman from a group of women in reporductive age. I’ve tried to create a roster only with women with this characteristics (age>15 && sex==2) and then try to random select one from this Aray doing the following:

SelectKish1949((long)((Quest.IRnd()*8)+1),(wml.Count(x=> x.@rowcode>0)))

***where wml is the name of the roster of women in reproductive age

However, since the @rowcode is kept from the main roster, the random selected number may not necessarily be specific for a woman in reproductive age.

What is the best way to go over this? Is there a syntax that could allow me to random select from a group of these women?

Thanks for your support

Dear Andres,

the Kish table doesn’t have any built-in mechanism to specify eligibility, hence you need to do additional preparations before using it, and additional mapping after using it. I assume counting the number of the eligible members is not a problem, and correspondingly you can determine the selected person’s index among the eligible with the Kish table, but then you will need to map it back to the original rowcodes.

members.Where(x=>x.age>15 && x.sex==2).Select(x=>x.@rowcode).ToArray()

will give you an array of rowcodes which you can utilize for this mapping. Note also that the arrays in C# are zero-based.

Best, Sergiy

Dear Katharina,

I need some more information about what “this doesn’t work” means. It could be anything from the user typed the condition into the wrong field of the questionnaire designer, to syntax error in expression.

Just from looking into the expression, most likely there are multiple problems:

  1. the expression in the [-- brackets --] is not integer, causing a syntax error. But I don’t see the definition of either random, sex, or age.
  2. the expression typed is not a logical expression. I don’t see where have you typed it into. If this is written in the enabling condition, then you must construct an expression which takes a value of TRUE for the selected person and FALSE for any ones not selected.

Best, Sergiy