register_order
register_order(name, levels, vars=None, prefixes=None, overwrite=True)Register a reusable ordinal level order.
Survey scales (education, Likert, frequency, …) have a natural order that is tedious to retype as levels=[...] every time. Register an order once, link it to the variable names and/or column prefixes it applies to, and the tabulating helpers (e.g. calc_percentage()) will look it up and apply it automatically. Persist your orders in a profile with save_ezrsurvey_profile().
An order links a set of levels to the columns it applies to, by exact name (vars) and/or by prefix (prefixes). Once registered, calc_percentage(), calc_percentage_multi() and crosstab() look it up automatically (via order_for()) whenever you don’t pass an explicit levels/sort, so a question always comes out in the right order without retyping it.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| name | str | Short name for the order (e.g. “education”). | required |
| levels | list of str | The levels in ascending order. | required |
| vars | str or list of str | Exact column names this order applies to (e.g. “demo_edu”). | None |
| prefixes | str or list of str | Column-name prefixes this order applies to (e.g. “edu_”). A variable matches if its name starts with any prefix. | None |
| overwrite | bool | Overwrite an existing order of the same name. Default True. | True |
Returns
| Name | Type | Description |
|---|---|---|
| str | The order name. |
See Also
order_for, apply_order, list_orders, register_order_presets
Examples
>>> register_order(
... "education",
... levels=["Primary or less", "Lower secondary", "Upper secondary",
... "Short-cycle tertiary", "Bachelor or equivalent",
... "Master or equivalent", "Doctoral or equivalent"],
... vars="demo_edu",
... )
>>> calc_percentage(podracing_survey, "demo_edu")
>>> remove_order("education")