See Crunch Automation basics for more information.
The CREATE FILTER command allows you to create filters for a dataset. All filters created are public filters, viewable and usable by anyone who has access to the dataset.
The filter is simply based on a condition based on boolean logic, which takes the cases into the filter that evaluates to TRUE.
Most importantly, filters are not variables, so you won’t be able to view them in the Variable Sidebar on the left in the Crunch web app. Filters are only found in the filter drop-down menus in the app. It is for that reason that there is no “AS” part of the command (because you’re not storing the filter as a variable).
For more details on how to write conditions/expressions, see our Expressions section of the Crunch Automation basics guide.
You should express the condition:
- For categorical variables — to the category id and not the assigned numeric value.
- For numeric variables — to the numeric value.
For that reason, you may wish to use the “labels” instead of codes when working with categorical variables. For example, var_gender = "Female" rather than var_gender = 2, because it may be unclear if “Female” has a category code of 1 or 2.
CREATE FILTER condition NAME "string";
Suppose we want to create a filter for a certain time period. This can be done by expressing the following inequality using dates:
CREATE FILTER wave_date >= 2019-07-01 AND wave_date < 2019-10-01 NAME "2019 Q3";
Using another simple example, we can create a filter for young males:
CREATE FILTER gender = “Male” AND age_group = “18 - 29” NAME "Young Males";