TapCub is live — analytics, insights and live chat, free on one platform
Glossary

What is a categorical variable? Definition, examples and tests

A categorical variable holds labels for groups, not amounts. The arithmetic test for spotting one, 10 tracked properties judged, how to summarize categories, and a worked chi-square example.

Lin Zhou Reviewed by Su He Also called categorical data Last updated Nov 15, 2026 Glossary

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:

PropertyExample valueTypeWhyHow to summarize
countryDECategorical (nominal)Labels with no orderCount, share, mode
planproCategorical (ordinal)Ordered tiers, unequal gapsCount, share, median tier
zip_code10115Categorical (nominal)Averaging two ZIP codes gives a meaningless numberCount, share by region
http_status404Categorical (nominal)404 is not "twice" 200Count, share of 4xx and 5xx
app_version3.8.0Categorical (ordinal)Releases are ordered, but 3.8 − 3.7 is not an amountShare of active users per version
error_codeE1042Categorical (nominal)An identifier, even if stored as a numberCount, top-N list
is_returningtrueCategorical (binary)Two statesProportion of true
csat_score4Categorical (ordinal)A 1–5 rating has order, not equal stepsDistribution, median, top-two share
order_value59.90Quantitative (continuous)Sums and averages are real moneySum, mean, median, percentiles
items_in_cart3Quantitative (discrete)Counts add upSum, 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:

  1. Frequency (count): how many observations fall into each category. Example: 1,840 sessions from Germany.
  2. Relative frequency (share): count ÷ total. 1,840 of 9,200 sessions = 20.0%.
  3. Mode: the most common category. It is the only measure of "center" that works for nominal data.
  4. 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.

DeviceSigned upDid notTotalSignup rate
Desktop609401,0006.0%
Mobile601,4401,5004.0%
Total1202,3802,5004.8%

Step by step:

  1. 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.
  2. 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.
  3. Chi-square = 3.00 + 0.15 + 2.00 + 0.10 = 5.25, with (2 − 1) × (2 − 1) = 1 degree of freedom.
  4. 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 02134 stored as a number becomes 2134, and the leading zero is gone. Codes and IDs belong in text fields; see data types.
  • Inconsistent labels. US, USA and United States split 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:

  1. 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_status and error_code to String, is_returning to Boolean, and keep Number for order_value and items_in_cart. Once you save an edit, later scans do not overwrite the type.
  2. 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 stops USA and United States from becoming two categories.
  3. 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.
  4. 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

Was this explanation clear?

We use your answers to fix and expand this page.

Lin Zhou

Product Experience Specialist

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

FAQ

Questions people ask

Short answers to the follow-up questions that come up most.

Still have a question?

Chat with the team behind TapCub — we usually reply within a few hours on business days.

What is an example of a categorical variable?

Country, browser, traffic channel, payment method and subscription plan are categorical variables. So are values written in digits that only label something, such as ZIP codes, HTTP status codes, error codes and app version numbers. A useful check: if the average of two values means nothing, the variable is categorical.

Is age a categorical or quantitative variable?

Age in years is quantitative: differences and averages make sense, and 40 is twice 20. It becomes categorical once you group it into bands such as 18–24, 25–34 and 35–44. The bands are ordinal, so you can sort them, but you lose the exact values and can no longer average them.

Can a categorical variable be a number?

Yes. Many categorical variables are stored as numbers: plan IDs 1/2/3, status code 404, rating 4 out of 5. Storage format does not decide the type. What decides it is whether arithmetic on the values gives something meaningful. The mean of status codes 200, 404 and 500 is 368, which is not a status.

How do you analyze two categorical variables?

Build a cross-tab of counts, compare the shares in each row, and test whether the variables are independent with a chi-square test. Compute expected counts as row total times column total divided by the grand total, then sum (observed minus expected) squared over expected for every cell.

See this number on your own site

Add one script tag for web and apps, and the first reports fill in within minutes.

See your data clearly. Find your growth.

Every click, backed by data. Install one line of code and see your first numbers in a minute.

No credit card · Free plans for analytics and chat · Cookieless analytics