Quick answer
A categorical variable is a variable whose values are labels for groups, such as country, plan or error code, not measured amounts. Test it by asking whether adding or averaging the values means anything: ZIP codes and status codes are digits but still categories.
Formula: χ² = Σ (observed − expected)² ÷ expected, where expected = row total × column total ÷ grand total
What is a categorical variable?
A categorical variable is a variable whose values are labels for groups, not amounts. Each observation falls into one of a limited set of categories: a visitor's country, the browser they use, the plan they are on, the error code a request returned. Statisticians also call it a qualitative variable; in S. S. Stevens' levels of measurement it covers the nominal and ordinal scales.
The test that matters in practice is simple: would adding, subtracting or averaging the values mean anything? If not, the variable is categorical, even when every value is a number. ZIP codes, HTTP status codes, error codes and version numbers are all written in digits, and all of them are categories. Get the type wrong and the chart, the summary statistic and the significance test that follow are wrong too.
Nominal vs ordinal categorical variables
Categorical variables come in two kinds:
- Nominal: the categories have no natural order. Country, browser, traffic channel, payment method and error code are nominal. You can count them and compare shares, but "Chrome is greater than Safari" has no meaning.
- Ordinal: the categories have an order, but the steps between them are not equal. Plan tier (free, pro, business), satisfaction from 1 to 5 and priority (P1–P4) are ordinal. You can sort and take a median; the ordinal variable entry explains why averaging them misleads.
A categorical variable with exactly two values (logged in or not, converted or not) is called binary or dichotomous. Binary variables are often stored as true/false or 1/0, and the share of 1s is a proportion, which is why conversion rate works even though "converted" is a category.
Categorical or quantitative? 10 tracked properties judged
The fastest way to decide is to apply the arithmetic test to real event properties. Sample property set from an online store:
| Property | Example value | Type | Why | How to summarize |
|---|---|---|---|---|
country | DE | Categorical (nominal) | Labels with no order | Count, share, mode |
plan | pro | Categorical (ordinal) | Ordered tiers, unequal gaps | Count, share, median tier |
zip_code | 10115 | Categorical (nominal) | Averaging two ZIP codes gives a meaningless number | Count, share by region |
http_status | 404 | Categorical (nominal) | 404 is not "twice" 200 | Count, share of 4xx and 5xx |
app_version | 3.8.0 | Categorical (ordinal) | Releases are ordered, but 3.8 − 3.7 is not an amount | Share of active users per version |
error_code | E1042 | Categorical (nominal) | An identifier, even if stored as a number | Count, top-N list |
is_returning | true | Categorical (binary) | Two states | Proportion of true |
csat_score | 4 | Categorical (ordinal) | A 1–5 rating has order, not equal steps | Distribution, median, top-two share |
order_value | 59.90 | Quantitative (continuous) | Sums and averages are real money | Sum, mean, median, percentiles |
items_in_cart | 3 | Quantitative (discrete) | Counts add up | Sum, mean per order, distribution |
Eight of the ten are categorical, and four of those eight are stored as digits. That ratio is typical for analytics data, where IDs, codes and ratings outnumber true measurements. The quantitative side is covered in quantitative data.
How to summarize categorical data
Because you cannot average labels, categorical data is summarized by counting:
- Frequency (count): how many observations fall into each category. Example: 1,840 sessions from Germany.
- Relative frequency (share): count ÷ total. 1,840 of 9,200 sessions = 20.0%.
- Mode: the most common category. It is the only measure of "center" that works for nominal data.
- Cross-tabulation: counts for two categorical variables at once, such as device × converted. This is where most useful comparisons happen.
For charts, use bar charts sorted by count, or stacked bars for shares. A histogram is for quantitative data; on categories it implies a continuous axis that does not exist. Pie charts work only for a handful of categories that add up to a whole.
When a variable has hundreds of distinct values, such as a free-text city field, its cardinality is high: most categories have too few observations to compare. Group the long tail into "other" or map values to a coarser level (city to country) before summarizing.
Testing two categorical variables: a chi-square example
The standard question for two categorical variables is whether they are independent: does the share of signups differ by device, or is the difference just noise? Pearson's chi-square test of independence answers it by comparing observed counts with the counts you would expect if there were no relationship.
Sample data: 2,500 visitors to a signup page, split by device.
| Device | Signed up | Did not | Total | Signup rate |
|---|---|---|---|---|
| Desktop | 60 | 940 | 1,000 | 6.0% |
| Mobile | 60 | 1,440 | 1,500 | 4.0% |
| Total | 120 | 2,380 | 2,500 | 4.8% |
Step by step:
- Expected count for each cell = row total × column total ÷ grand total. Desktop signed up: 1,000 × 120 ÷ 2,500 = 48. Desktop did not: 952. Mobile signed up: 72. Mobile did not: 1,428.
- Each cell's contribution = (observed − expected)² ÷ expected: (60 − 48)² ÷ 48 = 3.00; (940 − 952)² ÷ 952 = 0.15; (60 − 72)² ÷ 72 = 2.00; (1,440 − 1,428)² ÷ 1,428 = 0.10.
- Chi-square = 3.00 + 0.15 + 2.00 + 0.10 = 5.25, with (2 − 1) × (2 − 1) = 1 degree of freedom.
- Compare with the critical value 3.84 at the 5% level. 5.25 is larger, so the signup rate depends on device (p ≈ 0.022).
Notice what the test needs: counts per category, not averages. If device had been coded as 1 and 2 and averaged, there would be nothing to test. For a quick check of your own table, use the chi-square calculator.
Using categorical variables in models
Regression and most machine-learning models need numbers, so categories are converted with dummy (one-hot) coding: one 0/1 column per category, leaving one category out as the baseline. A channel variable with four values (organic, paid, email, direct) becomes three columns; the model's coefficients then compare each channel with direct. Feeding the raw codes 1–4 instead tells the model that email (3) is "between" paid (2) and direct (4), which is false.
Common mistakes with categorical variables
- Averaging numeric codes. The mean of status codes 200, 404 and 500 is 368, which is not a status. The mean of plan IDs coded 1/2/3 for ten customers (five free, three pro, two business) is 1.7, which is not a plan.
- Storing codes as numbers. ZIP code
02134stored as a number becomes2134, and the leading zero is gone. Codes and IDs belong in text fields; see data types. - Inconsistent labels.
US,USAandUnited Statessplit one category into three and shrink every count. Fix values at collection with an allowed list. - Too many categories. Twenty categories with 15 observations each cannot support any comparison; merge them first.
- Ignoring order. Treating an ordinal variable as nominal is not wrong, but it throws away information; a test that uses the order is usually more sensitive.
Qualitative vs quantitative data compares the two families more broadly, and qualitative data covers research methods such as interviews.
Categorical properties in TapCub
The 10 properties above are the kind of list a team defines when it sets up tracking. In TapCub the type decision is made once, in the property dictionary, and then holds for every report:
- Set the type. All-platform analytics › Data › Property dictionary lists each event property with its type: String, Number, Boolean, Datetime or List. Set
zip_code,http_statusanderror_codeto String,is_returningto Boolean, and keep Number fororder_valueanditems_in_cart. Once you save an edit, later scans do not overwrite the type. - Keep labels clean. In the same place, a validation rule can require an expected type or a list of allowed values, and a governance whitelist stores any other value as
__other. That stopsUSAandUnited Statesfrom becoming two categories. - Watch cardinality. The data quality page flags high-cardinality properties based on distinct values over 7 days, which is the signal to group the long tail.
- Compare groups, not averages. In All-platform analytics › Behavior › Behavior analysis, break event analysis down by up to three dimensions, or break a funnel down by one dimension such as country or device (the funnel keeps the 10 groups with the most entries). The signup table above is one funnel broken down by device; take the step counts from it and run the chi-square test on them.
See also: What is categorical data? Types, examples and how to analyze it.
See also: Is Year Categorical or Quantitative? A Decision Table.
Sources
- Stevens, S. S. (1946). On the Theory of Scales of Measurement. Science, 103(2684), 677–680.
- NIST/SEMATECH e-Handbook of Statistical Methods, 7.4.5 How can we compare the results of classifying according to several categories? (contingency tables and the chi-square test).
- UCLA OARC Statistical Consulting, What is the difference between categorical, ordinal and interval variables?
Was this explanation clear?
We use your answers to fix and expand this page.
Couldn’t send. Please try again in a minute.
Thanks for the feedback. We’ll use it to improve this page.You’ve already sent feedback on this page. Thanks.

Product Experience Specialist
Writes about product experience, practical workflows, and growth, turning complex processes into clear steps for everyday decisions.