Quota examples

Here are some examples where you can use quota functions to allocate a respondent to a quota cell depending on the respondent's previous answers and on which quota cells are not yet full.

Example #1 – allocating quota based on respondent’s answers to a Multi and which quota cells are not yet full:

Let's say you have a survey where you want the respondent to evaluate one brand only out of all the brands they have heard of. You have a quota on each brand so if the respondent has selected 3 brands that they’ve heard of, you want to allocate them to a brand where the quota is not yet filled.

For this we will have 3 questions listing the brands:

• Brands_known – a multi question where the respondent selects which brands they've heard of
• Brands_avail – a hidden multi question where answers are switched on by script if (a) they are selected in brands_known and (b) the quota cell for that brand is still open
• Brands_quo – a single question which is masked, only showing answers selected in brands_avail; a quota is based on this question

This is the structure of the questionnaire tree:

Example 1 Questionnaire Tree

The script, s1, is where brands are switched on brands_avail if (a) they have been selected in brands_known and (b) the quota cell for that brand is still open. The script required is:

var answers = f('brands_known').categories();    //get an array of selected answers in brands_known
for(var i : int=0;i<answers.length;i++)    //iterate through all the codes
  {
  var code = answers[i];    //current answer code
  f('brands_avail')[code].set(null);     //first switch off code in brands_avail in case resp amends answers
  f('brands_quo').set(code);     //switch on the answer in the quota var
    if(!(qf('BrandQuota')))     //check if the quota is not full for this answer
    {
    f('brands_avail')[code].set('1');    //if quota not full, switch on answer in brands_avail
    }
  }
f('brands_quo').set(null);     //set the var used in quota to null so it is unanswered when visible to resp

A condition is added after the s1 script to check if there are any open quotas for the brands that the respondent has heard of. The condition is:

f('brands_avail').size()==0

If the condition evaluates to True then the respondent is terminated in the survey via a Stop node and their status set to Quota Full.

If the condition evaluates to False then the respondent continues with the survey and is presented with the brands_quo single question where they can select which brand they would like to evaluate for the survey.

Example #2 – allocating quota based child Age/Gender:

Let's say you have a survey where you want the respondent to complete the survey on behalf of only one of their children. Quotas are based on a combination of the child's age group & gender. Respondents should first select which age/gender children they have. Their answers are then checked against open quota cells. If there are still open quotas for the age/gender of the respondent's child(ren) then they are presented with a single question where they can select which child (age/gender) they wish to complete the survey for.

For this we will have 4 questions:

Q1 - Multi – lists all age years by gender, ie:
3yr boy – answer code 2
4yr boy – answer code 3
etc......
16 yr boy – answer code 15
17 yr boy – answer code 16
3 yr girl – answer code 18
4 yr girl – answer code 19
etc......
16 yr girl – answer code 31
17 yr girl – answer code 32
OpenQuotas – hidden multi – same answerlist as q1; will be populated by script with only answers selected in q1 that still have open quota cells
Q2 - Single – same answerlist as q1 & Open Quotas; masked on OpenQuotas question
ChildAgeGroup – hidden single, used for quota – answerlist is age groups, ie:
3-11 yrs – answer code 1
12-15 yrs – answer code 2
16-17 yrs – answer code 3
ChildGender – hidden single, used for quota – answerlist is Male (answer code 1) & Female (answer code 2)

This is the structure of the questionnaire tree:

Example 2 questionnaire tree

A quota is defined (ChildAgeGender) based on ChildAgeGroup & ChildGender hidden single questions. The quota cells are as follows:

Male 3-11yrs
Male 12-15yrs
Male 16-17yrs
Female 3-11yrs
Female 12-15yrs
Female 16-17yrs

So in q1 the respondent selects which age/gender children they have.

The script s1 then checks which quota cell the answers in q1 fall into (based on ChildAgeGroup & ChildGender) and whether that quota cell is full – if the quota cell is not full then the appropriate answer is switched on in the hidden OpenQuotas question. This is the script required in s1:

var answers = f('q1').categories();    //get an array of selected answers in q1
for(var i : int=0;i<answers.length;i++)    //iterate through all the codes
  {
  var code = answers[i];     //current answer code
  f('OpenQuotas')[code].set(null);     //first switch off answer in OpenQuotas (in case res amends answers)
//a series of If statements follows to switch on the appropriate answer in ChildGender & ChildAgeGroup
  if(set('2','3','4','5','6','7','8','9','10').inc(code))
    { f('ChildAgeGroup').set('1')
    f('ChildGender').set('1') }
  if(set('11','12','13','14').inc(code))
    { f('ChildAgeGroup').set('2')
    f('ChildGender').set('1') }
  if(set('15','16').inc(code))
    { f('ChildAgeGroup').set('3')
    f('ChildGender').set('1') }
  if(set('18','19','20','21','22','23','24','25','26').inc(code))
    { f('ChildAgeGroup').set('1')
    f('ChildGender').set('2') }
  if(set('27','28','29','30').inc(code))
    { f('ChildAgeGroup').set('2')
    f('ChildGender').set('2') }
  if(set('31','32').inc(code))
    { f('ChildAgeGroup').set('3')
    f('ChildGender').set('2') }
  if(!(qf('ChildAgeGender')))     //check if the quota is not full for this answer
    { f('OpenQuotas')[code].set('1'); }    //if quota not full, switch on answer in brands_avail
  }
f('ChildAgeGroup').set(null);    //set the var used in quota to null
f('ChildGender').set(null);    //set the var used in quota to null
The respondent is then presented with the single question, q2, which is masked on the OpenQuotas question, so it will only show the answers (age in years by gender) that the respondent selected in q1 and which still have open quotas.

The script s4 switches on the appropriate answer in ChildAgeGroup and ChildGender (the quota variables) according to what the respondent selects in q2. The script required in s4 to do this is:

if(f('q2').any('2','3','4','5','6','7','8','9','10','11','12','13','14','15','16'))
  { f("ChildGender").set("1"); }     //male
if(f('q2').any('18','19','20','21','22','23','24','25','26','27','28','29','30','31','32'))
  { f("ChildGender").set("2"); }    //female
if(f('q2').any('2','3','4','5','6','7','8','9','10','18','19','20','21','22','23','24','25','26'))
  { f("ChildAgeGroup").set("1"); }    //age 3-11 yrs
if(f('q2').any('11','12','13','14','27','28','29','30'))
  { f("ChildAgeGroup").set("2"); }    //age 12-15 yrs
if(f('q2').any('15','16','31','32'))
  { f("ChildAgeGroup").set("3"); }     //age16-17 yrs

So now the hidden questions ChildAgeGroup and ChildGender will be populated according to what the respondent selected in q2 and since the quota is based on ChildAgeGroup & ChildGender then the respondent will be allocated to the appropriate quota cell.

Example #3 – allocating quota to the lowest current quota cell:
Assume for example that you are performing a survey to evaluate respondents' feelings about five different web page layouts, but you want each respondent to only evaluate one of the layouts. You also want the respondents to be evenly distributed across the five layouts. You could use the following script to select which layout a respondent is shown:

var form = f('q1')
var codes = form.domainValues();
var count = 2000;     //a value higher than your highest quota target
var code;
var lowestCode;

/*Loops through all the alternatives in q1 and checks whether the quota count is lowest with that answer*/
for(var i: int=0; i<codes.length; i++) {
  var code = codes[i];
  form.set(code);
  if( qc("quota1") < count ) {
    count = qc("quota1");
    lowestCode = code;
  }
}
form.set(lowestCode);

Here "q1" is the question id for the question with an answer per web page layout tested (should normally be a hidden question). "quota1" is the quota id for the quota used in the survey. Now you can create skip logic in the survey based on q1.
Note, it is important that the quota ‘quota1’ does not have any quota cells set to ‘Any’ for this example as if that is the case then the respondent will qualify for several quota cells and therefore the qc() function will return -1 which will stop the script working as required.