Dummy Variables
See how 0-or-1 variables let a regression handle categories like seasons or yes-or-no features, and how to avoid the dummy trap.
Key takeaways
- A dummy variable equals 1 when a condition is true and 0 when it is not.
- The coefficient on a dummy is the average difference between the group marked 1 and the group marked 0, holding the other variables fixed.
- With a category that has several groups, you create one dummy for each group except one, which becomes the baseline.
- Including a dummy for every group along with an intercept breaks the regression; this is the dummy variable trap.
- Which group you leave out changes how the numbers look, but not what the model predicts.
Regression loves numbers: square feet, dollars, miles, minutes. But a lot of what shapes the economy is not a number at all. Does a café have a drive-thru window? Is a month in winter or summer? Did a state raise its minimum wage this year? Is the worker a union member? These are yes-or-no facts and labels, and you cannot multiply "winter" by a slope.
So how do you get a category into a regression? You give it a number, and you pick the plainest number possible: 1 if the thing is true and 0 if it is not. That little trick is called a dummy variable, and it lets one regression compare groups, track seasons and measure the effect of a policy. The name sounds rude, but nobody is calling anyone dumb. It just means a stand-in for a category. Some books say indicator variable or binary variable, which means the same thing.
One dummy, one comparison
Picture Dev, who is studying ten cafés in a mid-sized city. For each café he knows its average weekly sales, and whether it has a drive-thru window. He defines:
Drive = 1 if the café has a drive-thru, 0 if not Say five cafés have no drive-thru and average $4,000 a week, and five have one and average $5,200. Now regress sales on Drive alone:
Sales = b0 + b1 × Drive What do the coefficients turn out to be? For a café with no drive-thru, Drive = 0, so the model predicts b0. The best prediction for that group is its average, so b0 = 4,000. For a café with a drive-thru, Drive = 1, so the model predicts b0 + b1. That must be the average of the second group, 5,200, so b1 = 5,200 − 4,000 = 1,200.
That is the whole secret. The intercept is the average for the group coded 0. The slope on the dummy is the gap between the two group averages. With only a dummy in the model, regression just reproduces a comparison of two means. The t test on b1 is the standard test of whether two group averages differ (see the standard errors lesson).
Dummies earn their keep in multiple regression
A raw gap of $1,200 may be misleading. Maybe drive-thru cafés also happen to be bigger. In the multiple regression lesson we learned to add variables so each coefficient is measured with the others held fixed. Dev adds size, measured in hundreds of square feet, and the drive-thru dummy sits beside it.
To keep the picture simple, take a different setting for the graph: apartment rent. Suppose a regression of monthly rent (in hundreds of dollars) on size (in hundreds of square feet) and an elevator dummy gives:
Rent = 4 + 1.2 × Size + 1.5 × Elevator For a 700-square-foot apartment (Size = 7) in a building with no elevator, Rent = 4 + 1.2 × 7 = 4 + 8.4 = 12.4, which is $1,240. With an elevator, Rent = 12.4 + 1.5 = 13.9, which is $1,390. The elevator adds $150 a month at every size, holding size fixed.
On a graph, that is two parallel lines. The dummy does not change the slope. It shifts the whole line up by the size of its coefficient.
Both lines climb 1.2 per 100 square feet. The elevator line sits 1.5 higher everywhere.
This is why dummies are so handy. One regression, one slope for size, and a clean statement about how much the feature is worth after accounting for size.
When a category has more than two groups
Seasons have four groups. Do you code winter as 1, spring as 2, summer as 3, fall as 4? Please do not. That would force the regression to treat summer as "three times winter" and to assume equal steps between seasons. Categories are labels, not quantities.
Instead you build one dummy per group:
Spring = 1 in spring months, else 0
Summer = 1 in summer months, else 0
Fall = 1 in fall months, else 0 Notice that Winter is missing. Winter is the baseline (also called the reference group or omitted category): when Spring, Summer and Fall are all 0, you are in winter. Suppose Dev tracks the weekly sales of one café and finds:
Sales = 3,000 + 400 × Spring + 900 × Summer + 200 × Fall Every coefficient is read against the baseline:
- Winter: 3,000 (all dummies zero).
- Spring: 3,000 + 400 = 3,400.
- Summer: 3,000 + 900 = 3,900.
- Fall: 3,000 + 200 = 3,200.
So the summer coefficient, 900, means "summer weeks average $900 more than winter weeks." It does not say anything directly about summer versus fall. For that, subtract: 900 − 200 = 700, and indeed 3,900 − 3,200 = 700.
Hypothetical example: the numbers are made up to show the method, not a quote or an average.
The dummy variable trap
A tempting thought: "Why leave winter out? Include all four dummies." Try it. For every row of the data, exactly one of Winter, Spring, Summer and Fall is 1 and the other three are 0. So:
Winter + Spring + Summer + Fall = 1 But the intercept is secretly a variable that equals 1 in every row. The four dummies add up to exactly that column of ones. One variable is a perfect copy of a combination of others, which means the regression cannot tell the intercept apart from the sum of the dummies. This is perfect multicollinearity, the extreme version of what you will meet in the multicollinearity lesson, and it violates one of the classical assumptions. Software will either refuse to run or quietly drop one of the dummies for you.
The rule is simple. For a category with g groups, include g − 1 dummies and keep the intercept. (Another route is to include all g dummies and drop the intercept, but then the coefficients mean something different, and most people prefer the baseline approach because it makes comparisons easy.)
Does the choice of baseline matter?
It changes how the table looks, but not what the model says. Switch the baseline to summer. Now we include Winter, Spring and Fall dummies, and the intercept becomes summer's average, 3,900:
Sales = 3,900 − 900 × Winter − 500 × Spring − 700 × Fall Check: spring is 3,900 − 500 = 3,400, the same as before. Fall is 3,900 − 700 = 3,200, the same. Every prediction is identical. What changed is which comparisons are visible as plain coefficients. Pick the baseline that makes your most important comparison jump out. If you care about how much better summer is than everything else, make summer the baseline. A good habit is to choose the largest group or the most natural "normal" group.
Testing all the dummies at once
Do seasons matter at all? Looking at three dummy t statistics one at a time has the same trouble you saw in the F test lesson. The right tool is an F test with q = 3 restrictions: Spring, Summer and Fall coefficients all equal zero. If F is large, the category matters, even if one or two individual dummies look weak.
Dummies for events and policies
Economists use dummies to mark events. Suppose a city opened a new bike lane in March, and Dev wants to know whether café sales changed. He creates a dummy called AfterLane that equals 0 for weeks before March and 1 for weeks after. If its coefficient is +250, then, holding the other variables fixed, weekly sales averaged $250 higher after the lane opened.
Be careful with the word "because." Maybe the weather warmed up in March too. That is why Dev keeps the temperature and season variables in the model, and why serious studies of policies use more careful designs than a single before-and-after dummy. A dummy gives you a clean measured gap. Whether the gap is a cause is a separate question you must argue for.
The last item on the right is a hint of what comes next. A plain dummy shifts the line but keeps the slope the same. When you suspect that the slope itself differs between groups, you need interaction terms.
Dummies with other kinds of outcomes
A dummy can also sit on the left side of the equation, as the thing being explained. If the outcome is "did the customer buy: 1 or 0," you are in the world of the linear probability, logit and probit models. For now, keep the dummy on the right side.
When the outcome is measured in logs, the dummy coefficient is read as roughly a percentage difference. A coefficient of 0.08 on a union-member dummy, in a regression of log wages, suggests union members earn about 8% more, holding the other variables fixed. The approximation works well for small coefficients and gets worse for large ones. The lesson on logs and functional form explains why.
Common mistakes
Coding a category as 1, 2, 3, 4. The regression will treat the numbers as real quantities and impose equal spacing. Use dummies.
Forgetting what the baseline is. A coefficient of +400 on Spring does not mean "spring sales are 400." It means 400 more than the baseline. State the baseline every time you read a result.
Falling into the trap. Including every group's dummy together with an intercept. Count your dummies: groups minus one.
Reading a dummy as proof of cause. Drive-thru cafés earning more does not prove that adding a window would raise your sales. Maybe drive-thrus are built on busy roads. A dummy tells you about differences in the data, and the correlation lesson still applies.
Words to know
Dummy variable a variable that equals 1 when a condition is true and 0 when it is not.
Baseline group the category left out, against which every other dummy coefficient is compared.
Dummy variable trap including a dummy for every group plus an intercept, which makes the regression impossible to estimate.
Intercept shift the upward or downward move of the whole regression line caused by a dummy.
Categorical variable a variable that sorts observations into labeled groups, such as season or region.
Perfect multicollinearity a situation where one variable is an exact combination of others.
Reference group another name for the baseline group.
Check yourself
- In a regression of sales on a drive-thru dummy alone, what does the intercept measure?
- Using the rent model Rent = 4 + 1.2 × Size + 1.5 × Elevator (rent in hundreds of dollars, size in hundreds of square feet), predict the monthly rent in dollars for a 900-square-foot apartment with an elevator.
- A region variable has five groups. How many dummies should you include alongside an intercept?
- In the season model Sales = 3,000 + 400 × Spring + 900 × Summer + 200 × Fall, how much more do summer weeks average than spring weeks?
- Explain why including all four season dummies and an intercept causes a problem.
- A student codes winter, spring, summer and fall as 1, 2, 3 and 4 and runs a regression. Explain what is wrong with that.
Show the answers
- It is the average outcome for the group coded 0, here cafés with no drive-thru.
- Size = 9, so Rent = 4 + 1.2 × 9 + 1.5 = 4 + 10.8 + 1.5 = 16.3, which is $1,630 a month.
- Four, which is the number of groups minus one.
- 900 − 400 = 500, so summer weeks average $500 more than spring weeks (3,900 − 3,400 = 500).
- The four dummies add up to 1 in every row, exactly matching the intercept column, so the regression cannot separate them; that is perfect multicollinearity.
- The numbers force equal spacing and a ranking between seasons that does not exist; categories need one dummy per group (minus the baseline) instead.