Skip to main content
v2026.11,986 entries · CC-BY 4.0

Indicator Variable Regression: Coding, Interpretation and Reporting

How indicator (dummy) variables work in regression: k – 1 coding, reference groups, a worked example, the dummy trap, reporting, and Excel, R and Python code.

Written and maintained by CASRAI Editorial Board

Published

On this page

An indicator variable in regression is a predictor coded 1 when an observation belongs to a category and 0 when it does not, which lets a linear model use categorical information such as gender, treatment arm or region. A category with k levels needs k − 1 indicators; the omitted level is the reference group, and each indicator’s coefficient is the adjusted difference in the outcome between its group and that reference group. This guide covers coding, a fully worked example with the arithmetic, interpretation, the dummy variable trap, reporting and code for Excel, R and Python.

Definition: what is an indicator variable in regression?

An indicator variable (also called a dummy variable) is a numeric variable that represents categorical data; it is easiest to interpret when coded 1 for presence and 0 for absence (Stat Trek). Harvard’s S-040 course defines MALEi = 1 if the student is male and 0 if female, and calls the group coded 0 the reference category (Harvard S-040, Unit 10). The 0/1 coding exists because ordinary least squares needs numbers: a text label such as “M” cannot be multiplied by a slope, but a 0/1 column can.

Indicator variables in regression versus dummy variables and one-hot encoding

“Indicator variable” and “dummy variable” name the same thing, and in machine learning the same construction is called one-hot encoding (Wikipedia). The practical difference is the number of columns: statistical regression with an intercept uses k − 1 columns, while one-hot encoding creates k. This guide stays on the statistical interpretation rather than machine-learning feature encoding.

Formula: the model and every symbol

For a continuous covariate and a two-group indicator the model is ŷ = b0 + b1·IQ + b2·X1, the form used in the Stat Trek example below.

  • ŷ: the predicted value of the outcome (here, a test score).
  • b0: the intercept, the prediction for the reference group when every other predictor equals 0.
  • b1: the slope of the continuous covariate (IQ), holding group constant.
  • X1: the indicator, 1 for the coded group (male) and 0 for the reference group (female).
  • b2: the coefficient of the indicator, the predicted difference between the coded group and the reference group at the same IQ.

With more than two categories you add one indicator per non-reference level. Stat Trek’s political-affiliation example has Republican (X1), Democrat (X2) and Independent as the reference group, giving Income = b0 + b1X1 + b2X2; a positive coefficient means the outcome is higher than in the reference group (Stat Trek).

Worked example with the arithmetic

The data are the ten-student example from Stat Trek: test score, IQ and gender. Score, IQ, gender: (93, 125, M), (86, 120, F), (96, 115, M), (81, 110, F), (92, 105, M), (75, 100, F), (84, 95, M), (77, 90, F), (73, 85, M), (74, 80, F). Code X1 = 1 for male and 0 for female. We fitted the model by ordinary least squares and checked every figure by solving the normal equations a second time with exact arithmetic on the same data.

Step 1: the group means (indicator only)

Male scores are 93, 96, 92, 84 and 73, which sum to 438, so the male mean is 438 ÷ 5 = 87.6. Female scores are 86, 81, 75, 77 and 74, which sum to 393, so the female mean is 393 ÷ 5 = 78.6. Regressing score on the indicator alone gives b0 = 78.6 (the reference-group mean) and b1 = 87.6 − 78.6 = 9.0 (the difference in means). Its standard error is 4.70, t(8) = 1.91, p = .092, which is exactly the pooled-variance two-sample t-test on the same data.

Step 2: add IQ as a covariate

The full model gives ŷ = 38.6 + 0.4·IQ + 7.0·X1. The standard errors are 9.54 (intercept), 0.094 (IQ) and 2.69 (male); the residual standard error is 4.18 on 7 degrees of freedom; R² = .810 and adjusted R² = .756. For the indicator, t(7) = 7.0 ÷ 2.686 = 2.61, p = .035, and the 95% confidence interval is 7.0 ± 2.365 × 2.686, or 0.65 to 13.35.

Two things change once IQ is in the model. The indicator coefficient falls from 9.0 to 7.0, because in this sample the male students also have higher IQs (mean 105 versus 100). It also becomes statistically significant, because IQ explains much of the residual scatter, shrinking its standard error from 4.70 to 2.69. The data table below sets out all four specifications side by side.

Step 3: change the reference group

Coding female as 1 and male as 0 gives ŷ = 45.6 + 0.4·IQ − 7.0·Xfemale. The intercept moves by exactly the old indicator coefficient (38.6 + 7.0 = 45.6), the indicator flips sign, and the fit, standard error, t statistic and R² are unchanged. Stat Trek makes the same point: the choice of reference group is arbitrary, and the analysis works equally well with female coded 1.

Interpretation: reading the coefficients

Read an indicator coefficient as a comparison with the reference group, with everything else in the model held constant. In the example, a male student is predicted to score 7.0 points higher than a female student of the same IQ.

Quantity How to read it Worked-example value
Intercept b0 Predicted outcome for the reference group when every other predictor is 0; it is only meaningful if 0 is a realistic value of those predictors 38.6 (a female student with IQ 0, an extrapolation)
Indicator, no covariates Difference between the two group means 9.0 = 87.6 − 78.6
Indicator, with covariates Adjusted difference between the coded group and the reference group at equal covariate values 7.0
Sign Positive: coded group higher than reference; negative: lower Positive for male, negative (−7.0) when female is coded 1
Changing the reference group Sign flips, magnitude and standard error stay the same, intercept shifts 45.6 and −7.0
Slope of a covariate Change in the outcome per one-unit increase, the same for both groups in this additive model 0.4 points per IQ point

If the intercept is meaningless because 0 is outside the data, centre the covariate. With IQ centred at its mean of 102.5, the intercept becomes 38.6 + 0.4 × 102.5 = 79.6, the predicted score of a female student of average IQ, and the male prediction is 79.6 + 7.0 = 86.6. For judging how large 7.0 points is, pair it with an effect size and a confidence interval; see also the general guide to the regression coefficient.

Assumptions and common mistakes

The dummy variable trap

If a model has an intercept and you include one indicator for every level, the last indicator is redundant: it equals 1 minus the sum of the others, which creates perfect multicollinearity and the model cannot be estimated uniquely. Stat Trek calls this the dummy variable trap and says k levels need k − 1 dummies. UC Davis’s regression help sheet gives the same rule: with a constant term, drop one of the mutually exclusive indicators, so do not include both male and female (Cameron, UC Davis).

Other mistakes to avoid

  • Not saying which group is the reference. A coefficient of 7.0 is uninterpretable until the reader knows what it is compared with. Always name the reference group.
  • Treating group codes as a number. Coding three groups as 1, 2, 3 and entering one variable forces equal spacing between groups. Use k − 1 indicators instead.
  • Summarising the indicator like an ordinary variable. The mean of a 0/1 indicator is the proportion coded 1, and its standard deviation is about √(p(1 − p)), largest at p = .5, so it is rarely reported; Harvard’s example has a MALE mean of .497 (91 boys, 92 girls). The same notes advise displaying results with bar plots or boxplots by the original category rather than histograms or scatterplots of the 0/1 values (Harvard S-040).
  • Assuming equal slopes. The model above gives both groups the same IQ slope. If the slope may differ by group, add an interaction between the indicator and the covariate; the homogeneity-of-regression-slopes check is the same idea.
  • Adding indicators for fit alone. Extra dummies raise in-sample R² but cost degrees of freedom (Wikipedia); with only 7 residual degrees of freedom here, each added parameter is expensive.

How to report an indicator variable regression

Report the coding, the reference group, the unstandardised coefficient with its uncertainty and the test. For the worked example:

Gender was coded 0 = female (reference) and 1 = male. Controlling for IQ, male students scored 7.0 points higher than female students, b = 7.00, SE = 2.69, t(7) = 2.61, p = .035, 95% CI [0.65, 13.35]; the model explained 81% of the variance in test scores, R² = .81, adjusted R² = .76.

State the sample size (n = 10), give exact p-values, and keep the coding statement in the methods section so that the sign of every coefficient can be interpreted. A p-value alone does not convey size, so keep the interval alongside it.

How to calculate it in Excel, R or Python

All three snippets reproduce the worked example. Each uses k − 1 = 1 indicator for two groups.

Excel

Put score in A2:A11, IQ in B2:B11 and gender text in D2:D11. In C2 enter =IF(D2="M",1,0) and fill down so the indicator sits in the column next to IQ. Then select a 5-row by 3-column range and enter =LINEST(A2:A11,B2:C11,TRUE,TRUE) as an array formula. LINEST returns coefficients in reverse order of the X columns, so the first row reads 7.0 (indicator), 0.4 (IQ), 38.6 (intercept). Never add a second indicator for the other group.

R

lm() expands a factor into dummy variables itself; model.matrix() shows the design matrix it builds, and its contrasts.arg argument overrides the default coding (R documentation: model.matrix).

d = data.frame(score = c(93,86,96,81,92,75,84,77,73,74),
  iq = c(125,120,115,110,105,100,95,90,85,80),
  gender = c("M","F","M","F","M","F","M","F","M","F"))
d$gender = factor(d$gender, levels = c("F","M"))   # first level = reference
fit = lm(score ~ iq + gender, data = d)
summary(fit)                          # genderM = 7.0
d$gender = relevel(d$gender, ref = "M")   # change the reference group
model.matrix(~ iq + gender, d)       # inspect the dummy column

Python

import pandas as pd
import statsmodels.formula.api as smf
d = pd.DataFrame({"score": [93,86,96,81,92,75,84,77,73,74],
  "iq": [125,120,115,110,105,100,95,90,85,80],
  "gender": list("MFMFMFMFMF")})
fit = smf.ols("score ~ iq + C(gender, Treatment(reference='F'))", data=d).fit()
print(fit.summary())   # the male coefficient is 7.0
# alternative: pd.get_dummies(d, columns=["gender"], drop_first=True)

With drop_first=True, pandas drops the first level alphabetically (F), leaving a single male column. Omitting it creates both columns, and fitting both with an intercept falls into the dummy variable trap.

Frequently asked questions

What is the difference between an indicator variable and a dummy variable?

None in regression: the two terms describe the same 0/1 variable that represents a category (Stat Trek). “Indicator” is the more formal label, “dummy” the more common one.

How many indicator variables do I need for a categorical predictor?

One fewer than the number of categories, if the model has an intercept. Three political affiliations need two indicators, with the third as the reference group.

How do I interpret the coefficient of an indicator variable?

As the predicted difference in the outcome between the coded group and the reference group, holding the other predictors constant. With no other predictors, it equals the difference in group means.

Does the choice of reference group change the results?

It changes the intercept and the sign of the indicator coefficient, but not the model fit, standard errors, t statistics or R². In the worked example the coefficient is +7.0 with male coded 1 and −7.0 with female coded 1.

Sources

Data: Regression estimates for the ten-student test-score example under four specifications

Coefficients, standard errors, t statistics and R-squared from ordinary least squares fits of test score on a male indicator, with and without IQ, and with each gender as the reference group. Computed by the author from the ten observations published by Stat Trek.

Period covered: 2026.

Regression estimates for the ten-student test-score example under four specifications
SpecificationReference groupInterceptIQ coefficientIndicator coefficientIndicator SEIndicator t statisticR-squared
Indicator only (male = 1)Female78.6n/a94.71.910.314
Indicator plus IQ (male = 1)Female38.60.472.692.610.81
Indicator plus IQ (female = 1)Male45.60.4-72.69-2.610.81
IQ only (no indicator)None37.750.442n/an/an/a0.626

Sources

Compiled by CASRAI from the sources above. Free to reuse under CC BY 4.0 with attribution.

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · free to try

Ask about Indicator Variable Regression: Coding, Interpretation and Reporting

2 free questions a day, no account.

An AI assistant for research: funder rules, compliance, methods and publishing. It links the sources behind its answers and labels answers that come from a web search.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays open to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →