Skip to main content

Quota Functions: quota and set_quota

Or making sure you only get who you want

Updated over 3 weeks ago

When and Why to Use

Use these together to enforce quota sampling in your survey. This helps control the composition of your sample by limiting how many respondents fall into each defined segment.

  • quota() defines a single quota line based on a condition

  • set_quota() groups multiple quota lines and enforces inclusion in one and only one

If a respondent does not match any defined quota or enters an over-quota group, they are terminated.

How It Works

  • Each quota() defines a named condition and a target proportion (as a float from 0 to 1)

  • set_quota() applies all defined quotas under a group name

  • Conditions can use any previous question responses

  • Respondents are checked live and quotas are updated in real-time

Configuration Options

quota(name, criteria, quota)

Parameter

Type

Required

Description

name

str

yes

Name of the quota line, used in reporting

criteria

bool

yes

Boolean expression that defines membership in this quota

quota

float

yes

Target proportion for this group (e.g., 0.25 for 25%)

set_quota(name, quotas)

Parameter

Type

Required

Description

name

str

yes

Name of the overall quota group

quotas

List[Quota]

yes

List of quota lines created using quota()

Example Code

from survey import Survey s = Survey(**globals()) age = s.numeric_question( question="How old are you?", min_max=(18, 100), recodes={ "0-17": "Under 18", "18-34": "18-34", "35-54": "35-54", "55-120": "55+" } ) gender = s.select_question( question="What is your gender?", options=["Male", "Female"] ) s.set_quota( name="Quads", quotas=[ s.quota("Younger Men", criteria=(age < 40) & (gender == "Male"), quota=0.25), s.quota("Older Men", criteria=(age >= 40) & (gender == "Male"), quota=0.25), s.quota("Younger Women", criteria=(age < 40) & (gender == "Female"), quota=0.25), s.quota("Older Women", criteria=(age >= 40) & (gender == "Female"), quota=0.25) ] )

Notes

  • Each respondent must meet one and only one quota condition

  • If all quotas are filled or a respondent does not meet any quota, they are terminated

  • You can use any boolean logic in the criteria to create flexible conditions

  • Proportions must sum to approximately 1.0 across all quotas in the group

Did this answer your question?