Skip to content
We use only essential cookies to keep you signed in and remember your preferences. See our Cookie Policy.
TestStop
MocksPracticeResourcesIndiaBlogPricing
Sign in
Resources › Econometrics › 5. Dummy variables
Econometrics · Lesson 5 of 18

Dummy variables, the dummy trap and interactions

Gender, region, season, a policy being in force: regressions need to take account of facts that are categories, not quantities. A dummy variable does it with a 0 or a 1. This lesson shows what a dummy does to the line (it moves it), what an interaction does (it tilts it), why a regression on a dummy is nothing more than a comparison of averages, and why including a dummy for every category as well as a constant makes the regression impossible to run.

← Econometrics moduleLesson 5 of 18 · about 55 minutes
1Multiple regression2Matrix form and Gauss-Markov3t and F tests4R² and adjusted R²5Dummies and interactions6Functional forms7Misspecification8Multicollinearity9Heteroscedasticity10Autocorrelation11Instrumental variables12Simultaneous equations13Panel data14Logit and probit15Unit roots16ARMA, VAR and cointegration17Test Atlas18Hard problems
A question to hold on to
We have estimated y = 10 + 1.5x + 4D, where y is earnings, x is experience, and D = 0 for females and 1 for males. If we had coded the dummy as −1 for females and +1 for males, the new estimated coefficients (in the same order) would have been: (A) 12, 1.5, −2; (B) 12, 1.5, 2; (C) 14, 1.5, −4; (D) 10, 1.5, 4.
Delhi School of Economics 2018Solved at the end ↓
New here?What is the Ashanagar survey?The invented household survey behind this page's examples: 600 households, generated from a model whose true coefficients we publish.

The Ashanagar survey is invented. The statistics modules used one district of 60 households. Econometrics needs more households and more variables, so this is a new, larger survey of 600 households in the same imaginary district: income, spending, household size, whether the household is in the town or a village, the head’s schooling and earnings.

Because we wrote the data-generating process, we know the true answers, and every lab can show whether a regression recovers them. Household spending, in thousands of rupees a month, was generated as 1 + 0.45 × income + 0.9 × household size + 1.5 × town + an error with standard deviation 2.5. A real survey never tells you its true coefficients. This one does, so you can see how close an estimate comes.

It also holds a variable, the head’s ability, that a real survey could not observe. It is kept so that the lessons on omitted variables can show what happens when it is left out. Every figure here is illustrative, not official statistics.

Households
600
Share in the town
41%
Mean monthly income
₹15.4 thousand
Mean monthly spending
₹12.6 thousand
Mean schooling of the head
8.2 years

How the module uses it →

In this guide
Lesson · about 55 minutes
  1. A dummy is a switch
  2. Shifting the intercept and the slope
  3. Many categories and the trap
  4. Recoding, and what stays put
  5. A kinked line
  6. ANOVA, ANCOVA and testing a gap
  7. The opening question, solved
  8. The lesson on one screen
  9. Check yourself
  10. Past papers, by level
01
The idea

A dummy is a switch

A dummy variable (also called an indicator or a binary variable) is 1 when an observation has some property and 0 when it does not. Put it in a regression next to a quantitative regressor and it works like a switch that adds a fixed amount to the prediction when the property holds:

One quantitative variable and one dummy
y=a+bx+dD+u
D = 1 for the group that has the property, 0 for the base group (also called the reference or omitted group). The coefficient d is the average gap between the two groups at the same x.

For a base-group member the prediction is a + bx. For a member of the other group it is a + bx + d. The two lines have the same slope b and differ by d everywhere, so they are parallel and d is called the differential intercept.

In the survey, 244 of 600 heads of household live in a town. Their earnings average 19.13 (₹ thousand a month) against 11.78 in villages, a gap of 7.35. Regress earnings on the town dummy alone and the coefficients are exactly these averages: intercept 11.78, dummy 7.35. The derivation shows why this must happen.

Derive it

A regression on one dummy returns the two group averages

We want to show
In y = a + d D + e, with D = 1 for one group and 0 for the other, least squares gives a = the average y of the group with D = 0 and d = the difference between the two group averages.
  1. 1
    Write the normal equations for this X.

    The columns of X are a column of ones and D. Let n₀ households have D = 0, n₁ have D = 1, and n = n₀ + n₁. Then X′X has n and n₁ on the diagonal and n₁ off it (the sum of D is n₁, and so is the sum of D²). X′y has the sum of all y and the sum of y over the D = 1 group:

    (nn1​​n1​n1​​)(ad​)=(∑all​y∑D=1​y​)
  2. 2
    Read off the second equation.

    n₁a + n₁d = ΣD=1 y. Divide by n₁: a + d = ȳ₁, the average y of the D = 1 group.

  3. 3
    Subtract it from the first.

    The first equation is na + n₁d = Σall y. Subtracting the second leaves (n − n₁)a = n₀a = ΣD=0 y, so a = ȳ₀, the average of the D = 0 group. Then d = ȳ₁ − a = ȳ₁ − ȳ₀.

  4. 4
    Check it on the survey.

    Of the 600 households, 356 are in villages and 244 in towns. The head’s average earnings are 11.7812 in villages and 19.1311 in towns, a gap of 7.35. The regression of earnings on the town dummy gives a = 11.7812 and d = 7.35. They match.

  5. 5
    The t test on d is the two-sample t test.

    The standard error of d is √(s²(1 ÷ n₀ + 1 ÷ n₁)), where s² is the residual variance, which here is the pooled within-group variance. That is the standard error of a difference between two means with a pooled variance: √(43.492 × (1 ÷ 356 + 1 ÷ 244)) = 0.5481, and the regression reports 0.5481. A regression with one dummy and an intercept is the equal-variance two-sample t test.

    If the dummy is coded the other way (1 for villages), the intercept becomes the town average and the coefficient becomes −d: the same two averages, written differently.

Step 1 of 5
So
Intercept = the base group’s average, dummy coefficient = the gap from the base. Add more dummies and each one is a gap from the same base. That is why the choice of base changes the coefficients but not the fitted values, the residuals or R².

Now hold other things constant. Add schooling and the head’s ability to the regression and the town coefficient falls to 3.04 (we wrote the model with a true town effect of 3). Most of the raw gap of 7.35 was town heads being better schooled and abler, not towns paying more for the same person. A dummy coefficient in a multiple regression is a gap at the same values of everything else in the model, and which controls are included changes what it measures.

Three small readings the exams ask for:

  • Averages from a dummy regression. If Ŵ = 400 − 60D for 300 people, 200 of them men (D = 1), women average 400 and men 340, and the sample average is 400 − 60 × 200 ÷ 300 = 360. The sample average is the intercept plus the dummy coefficient times the share in the group.
  • Precision. The variance of the estimated gap is σ²(1 ÷ n₀ + 1 ÷ n₁), the two-sample formula. With 300 people it is smallest when the groups are equal in size: 1 ÷ 150 + 1 ÷ 150 = 0.0133 against 1 ÷ 200 + 1 ÷ 100 = 0.015 for a 200/100 split. Lopsided groups give a less precise gap.
  • A dummy for a characteristic. In a house-price regression, a coefficient of −42.5 on a “flood-prone” dummy, with price in thousands of rupees, means a flood-prone house sells for about 42.5 thousand rupees (₹42,500) less than an otherwise identical house. The standard error and t test work as for any coefficient.
Watch out for

The mistakes examiners are fishing for

  • Reading the dummy coefficient as the gap between the groups’ raw averages. It is the gap holding the other regressors fixed. It equals the raw gap only when the dummy is the only regressor.
  • Forgetting which group is the base. d is “group 1 minus the base”. Swap the coding and the sign flips.
02
Interactive

Shifting the intercept and the slope

A dummy alone forces the two groups to have the same slope. If the payoff to schooling may differ between towns and villages, multiply the dummy by the quantitative variable and include the product, an interaction term:

Intercept shift and slope shift
y=a+bx+dD+g(D⋅x)+u
d shifts the intercept, g shifts the slope. The two groups now have different lines.
GroupInterceptSlope
Base group, D = 0ab
Other group, D = 1a + db + g

In the lab, choose between the dummy alone and the dummy with its interaction, code the dummy 0/1 or −1/+1, and move the slider to build a real extra payoff to schooling into town earnings. Watch the lines, and watch which coefficient carries which change.

Heads of household in the survey: earnings (₹ thousand a month) against years of schooling. Every fit also holds the invented ability score fixed, so the true values are known: schooling pays 1.3 and a town adds 3.

TermEstimateStd. errort
Intercept2.9370.27310.74
Schooling (years)1.2980.03537.09
Town (1) or village (0)3.0370.23512.93
Ability2.6850.10824.79
Village line: intercept, slope2.95, 1.3
Town line: intercept, slope5.99, 1.3
R²0.8911
Adjusted R²0.8906
2468101214165101520253035SchoolingEarnings

Horizontal: years of schooling of the head. Vertical: the head’s monthly earnings in ₹ thousand. Lines are drawn at average ability. Every third household is shown, nudged sideways so the points do not stack.

Village households and their lineTown households and their line
What it shows

The two lines are parallel: both rise 1.3 per extra year of schooling, and the town line sits 3.04 higher. That 3.04 is the average gap between a town head and a village head with the same schooling and ability (we wrote 3). It is the intercept shift.

600 households, 596 degrees of freedom.

Reading the interaction model:

  • g is the difference in slopes. A t test on g tests whether the payoff to x differs between the groups. In the survey with the slider at 0 the true difference is zero, because we wrote none, yet the t statistic comes out above 2: a false alarm. A 5% test gives one about one time in twenty, and the survey’s floor on earnings (nobody earns less than ₹1 thousand) makes it a little likelier. Raise the slider and the interaction picks up the extra payoff you build in. A t of 2.5 alone is not proof of a different slope.
  • d is the gap at x = 0 only. Once the interaction is in, the gap between the groups is d + g·x, which changes with x. The coefficient on D alone is the gap at x = 0, which may be a value nobody has (zero years of experience, zero income). Centre x on its mean if you want d to mean the gap at a typical x.
  • The coefficient on a variable that appears in an interaction is its effect for the base group. In y = α + βx + γUrban + θImmigrant + δUrban×Immigrant, θ is the difference between immigrants and non-immigrants who do not live in a city (Urban = 0). For city dwellers it is θ + δ.
  • To test whether the groups have the same line at all, test d = 0 and g = 0 together with an F test (lesson 3). That is the dummy-variable form of the Chow test for a structural break.
Pause and predict
In y = a + bx + dD + g(D·x), what is the effect of one more unit of x for a member of the group with D = 1?
Watch out for

The mistakes examiners are fishing for

  • Putting in an interaction without the dummy or the variable itself. Leaving out d forces the two lines to meet at x = 0, a restriction you rarely believe. Include the main effects unless theory says otherwise.
  • Calling g “the effect of the group”. It is how much the effect of x differs. The group’s own gap is d + g·x.
03
Interactive

Many categories and the trap

A variable with m categories (four seasons, five regions) needs m − 1 dummies when the regression has a constant. The omitted category is the base, and each dummy coefficient is a gap from it. The survey’s heads of household fall into three education groups, by years of schooling:

GroupHouseholdsAverage earnings
Primary (0 to 5 years)1376.028
Secondary (6 to 10 years)31214.262
Higher (11 or more)15123.753

Take primary as the base, with a constant and two dummies: the constant is 6.028, the secondary dummy is 8.234 (14.262 − 6.028) and the higher dummy is 17.725 (23.753 − 6.028). Now take secondary as the base: the constant becomes 14.262, and the other two coefficients become −8.234 and 9.491. Everything is rewritten, and nothing has changed: both regressions give the same fitted values, the same residuals and the same R², 0.6721. Try it, and then try to include all three dummies together with the constant.

Columns in the regression
TermEstimateStd. error
Intercept6.0280.368
Secondary8.2340.442
Higher17.7250.509
Fitted average, primary (actual 6.028)6.028
Fitted average, secondary (actual 14.262)14.262
Fitted average, higher (actual 23.753)23.753
R²0.6721
What it shows

Each dummy coefficient is a gap from the base group, primary: the constant 6.03 is that group's average earnings, and adding a dummy's coefficient gives the other group's average. The fitted averages match the actual ones, and R² (0.6721) is the same whichever group you make the base. Changing the base changes how the same three averages are written, not what the regression says.

The dummy-variable trap
D1​+D2​+⋯+Dm​=1 ⟹ X′X is singular
Every observation is in exactly one category, so the m dummies sum to 1 for everybody, which is exactly the constant column. One column of X is a combination of the others: the exact collinearity that lesson 2 ruled out.

There are two ways out, and both are standard:

  • Constant and m − 1 dummies. Each coefficient is a gap from the omitted group. R² is the usual R².
  • m dummies and no constant. Each coefficient is simply that group’s average (here 6.028, 14.262, 23.753). The regression is fine (the model y = β₁D₁ + β₂D₂ + ε with D₂ = 1 − D₁ can be estimated), but the R² a package prints is the uncentred one, 0.9327 here, which is not comparable with the R² of regressions that have a constant.

Two papers print “quantitative variable” where they mean a qualitative one with m categories; the rule is for qualitative variables, and with a constant the answer is m − 1 dummies. A regression that has a constant plus both a Pass and a Fail dummy cannot be estimated, for the same reason: Pass + Fail = 1.

Watch out for

The mistakes examiners are fishing for

  • Thinking the dummy trap is a problem of the data. It is a problem of how the model is written. No amount of extra data helps; dropping a column does.
  • Treating the base group as unimportant. Every dummy coefficient is relative to it, so a significant coefficient only says that group differs from the base. To compare two non-base groups, test the difference of their coefficients (an F or t test on a linear combination, lesson 3).
What to say in an exam

With a constant, a variable with m categories gets m − 1 dummies; using all m is perfect collinearity (the dummy-variable trap). Each dummy coefficient is a gap from the omitted base group, and the choice of base changes the coefficients but not the fitted values or R².

04
Same fit, different labels

Recoding, and what stays put

Recoding a dummy rewrites the same line in new coefficients. Suppose y = a + bx + dD with D = 0 or 1. Define a new variable E = 2D − 1, which is −1 for the base group and +1 for the other group, so D = (E + 1) ÷ 2. Substitute:

Recoding 0/1 as −1/+1
y=a+bx+d2E+1​=(a+2d​)+bx+2d​E
The slope b does not change. The intercept moves to the midpoint of the two groups' lines, and the dummy coefficient halves because E moves by 2 between the groups.
CodingInterceptCoefficient on xDummy coefficient
Base 0, other 1abd
Swap: base 1, other 0a + db−d
Base −1, other +1a + d ÷ 2bd ÷ 2

In every row the fitted values, the residuals, R² and the t statistic of the dummy (up to sign) are identical. Only what the numbers are called changes. The same is true of changing the base category with m groups (chapter 3), and of rescaling x (lesson 6), which changes b but not the dummy’s coefficient. Switch the lab above to −1/+1 coding and compare the lines.

05
A dummy for a threshold

A kinked line

Suppose the slope of spending on income changes once income passes a threshold X*, say 400. Two ways to write it:

  • Differential slope, jumps allowed: y = a + bX + cD·X, where D = 1 when X ≥ X*. The two lines have different slopes and the lines meet at X = 0, not at the threshold, so the prediction can jump at X*.
  • Piecewise linear (a kink): y = a + bX + c·D·(X − X*). The extra term is zero at X = X*, so the two pieces join there, and the slope is b below the threshold and b + c above it.

Take Ŷ = 100 + 0.5X − 0.2(X − 400)D. Below 400 the slope is 0.5; above, 0.5 − 0.2 = 0.3. At X = 400 both pieces give 100 + 0.5 × 400 = 300, so the line bends there without a gap. At X = 500 the prediction is 100 + 250 − 20 = 330. The coefficient on D·(X − X*) is the change in slope, and a t test on it tests whether the kink is real. This is the econometrics behind kinked Engel curves, tax schedules and piecewise-linear spline models.

06
Where dummies appear in exam papers

ANOVA, ANCOVA and testing a gap

  • Is there a gender difference, after controlling for the rest? Include a gender dummy next to the controls and test its coefficient (a t test). That is the simplest correct way to test it, and it is the survey’s town coefficient of 3.04 with its t statistic of 12.9.
  • ANOVA models have only dummy variables as regressors, so they compare group averages. ANCOVA models mix dummies with quantitative regressors, which is what the lessons above have been doing: the quantitative variable controls for something while the dummies compare groups.
  • Seasonal dummies. For quarterly data with a constant, three dummies for three quarters, the fourth being the base. Each coefficient is the average seasonal gap from the base quarter after the other regressors are held fixed.
  • A dummy as the dependent variable is a different model (a probability), covered with logit and probit in lesson 14.
In economics

Dummies are how most applied papers estimate a treatment effect: D = 1 for the treated, and the coefficient is the average difference between treated and untreated after controls. Whether that difference is the effect of the treatment depends on whether the groups differ in some other way the controls miss, which is lesson 7’s subject. The survey’s raw town gap of 7.35 against a controlled one of 3.04 is the warning.

07
Solving the opening question

The opening question, solved

Delhi School of Economics 2018 · moderate
y = 10 + 1.5x + 4D with D = 0 for females and 1 for males. The dummy is recoded −1 for females and +1 for males. What are the new coefficients, in the same order?
  1. 1
    Express the old dummy in terms of the new.
    Let E = −1 for females and +1 for males. Then D = (E + 1) ÷ 2: it is 0 when E = −1 and 1 when E = 1.
  2. 2
    Substitute into the equation.
    y = 10 + 1.5x + 4(E + 1) ÷ 2 = 10 + 1.5x + 2E + 2 = 12 + 1.5x + 2E.
  3. 3
    Read off the coefficients, in the order intercept, x, dummy.
    12, 1.5 and 2. Check with the predictions: a male at x = 0 had 10 + 4 = 14 and now has 12 + 2 = 14; a female had 10 and now has 12 − 2 = 10. The fitted values have not changed.
Answer
(B) 12, 1.5, 2. The slope on x is untouched, the intercept rises by half the old dummy coefficient, and the dummy coefficient is halved. Options A and C have the wrong sign for the dummy, and D forgets that the recoding moves the intercept.
08
Revise

The lesson on one screen

The lesson on one screen
Intercept shift
y = a + bx + dD: parallel lines, d is the gap at the same x (and the same other regressors).
Slope shift
y = a + bx + dD + g(D·x): the groups' slopes are b and b + g. d is then the gap at x = 0 only.
One dummy and a constant
The constant is the base group's average and d the difference between the averages. The t test on d is the two-sample t test.
m categories
m − 1 dummies with a constant, or m dummies without one. All m with a constant is the dummy trap: exact collinearity, X′X singular.
Changing the base
Rewrites the coefficients. Fitted values, residuals and R² do not change. (No constant: R² is uncentred, not comparable.)
Recoding 0/1 as −1/+1
Intercept a + d ÷ 2, dummy coefficient d ÷ 2, slope unchanged.
Kink
y = a + bX + c D (X − X*): continuous at X*, slope b then b + c.
ANOVA and ANCOVA
ANOVA: only dummies. ANCOVA: dummies and quantitative regressors.
09
Practice

Check yourself

0 of 13 correct so far

Compute

The sample average from a dummy regression
A regression of wages on a male dummy (1 for men) gives Ŵ = 400 − 60D for 300 people, of whom 200 are men. Find the sample average wage.
Precision of a gap
The gap between two groups is estimated from 300 people. The standard error of the gap is proportional to √(1 ÷ n₀ + 1 ÷ n₁). By what factor does it fall when the split changes from 200 and 100 to 150 and 150?
Recoding the dummy
ŷ = 8 + 2x + 6D, with D = 0 or 1. The dummy is recoded −1 and +1. Find the new intercept.
The slope for the dummy group
ŷ = 5 + 2x + 3D + 0.5(D·x). Find the slope of ŷ on x for the group with D = 1.
The gap at a given x
Using the same equation, ŷ = 5 + 2x + 3D + 0.5(D·x), find the difference in predicted y between the two groups at x = 10.
Where the two lines meet
ŷ = 5 + 2x − 4D + 0.5(D·x). At what value of x do the two groups have the same prediction?
Group averages from dummy coefficients
A regression of y on a constant and dummies for groups B and C (A is the base) gives constant 20, coefficient on B +5 and coefficient on C −3. Find the average y in group C.
A t statistic from the survey
In the survey, regressing earnings on the town dummy alone gives a coefficient of 7.350 with standard error 0.548. Find the t statistic.

Quick questions

1A regression with a constant has a qualitative variable with m categories. The number of dummies to include is
2Which of these regressions cannot be estimated by least squares?
3In y = a + bx + dD + g(D·x), the coefficient d is
4Changing which category is the base group in a regression with a constant changes
5An ANCOVA model is one whose regressors are
10
Real questions

Past papers, by level

Foundation

Definitions and one-step calculations: a t statistic, an R², which assumption is which. Most CUET and JNU questions sit here.

3 questionsPractise →

Standard

Restricted against unrestricted regressions, reading output, and statement questions, up to GATE and IIT JAM level.

4 questionsPractise →

Delhi School level

This topic’s hardest questions, from the DSE entrance, are worked through in Lesson 18: Dummy variables, recoding and kinks.

6 questionsLesson 18 →
All 7 past-paper questions for this lesson, easiest first: practise the full set →

✦These are questions from the TestStop bank. A free account answers 10 a day, each with its worked solution; All-Access opens every set with no daily limit.

The Delhi School’s questions on dummies (a dummy for gender and the most precise estimate of the gap, a poor-condition dummy in a home-sales regression, a kinked Engel curve) are in the hard-problems lesson at the end of the module. The case where the dependent variable is a dummy is in lesson 14, on the linear probability model, logit and probit.

← Lesson 4R², adjusted R² and comparing modelsLesson 6 →Logs, quadratics and units: reading a coefficient

Read next

All resources →
EconometricsEconometrics 6: log-log, semi-log and quadratic regressions, elasticity and unitsLevel-level, level-log, log-level and log-log regressions and how to read each coefficient, elasticity at the means, growth rates from a log-linear time trend, the quadratic's marginal effect and turning point, and what rescaling does to coefficients, on real World Bank data.Complete guide · 50 minEconometricsEconometrics 1: multiple regression, partial effects and holding other things constantThe multiple regression model, the normal equations, what a partial coefficient means and how partialling out shows it, the facts true of every OLS fit, reading a coefficient table, and standardised coefficients.Complete guide · 55 minEconometricsEconometrics for economics students, from multiple regression to time seriesA module in eighteen lessons, built on data where the truth is known: multiple regression, OLS in matrix form and the Gauss-Markov theorem, t and F tests, R squared, dummies, functional form and specification error, multicollinearity, heteroscedasticity and autocorrelation, endogeneity and instruments, simultaneous equations, panel data, binary outcomes, unit roots, ARMA, VAR and cointegration, then a test atlas that says which test fits which problem and the Delhi School's hardest questions, with graded past papers from every exam.Module · 935 min