Dummy coding is a simple, one of the most famous, and most common coding system for categorical variables. In dummy coding one of the categories of a categorical variable is referenced as based and analysis is interpreted considering the base of the original variable. Researchers use various approaches such as designating base as the group/category with the most observation, or category ranked as lowest or highest in the original variable which I will demonstrate below using education variable as an example.
Let’s demonstrate dummy coding using a real-life hypothetical example. Suppose you want to predict monthly expense using education (educ). Expense is in dollar value in hundred and a continuous variable. Age is a continuous variable representing the age of a person in years and education is a categorical variable with four categories: 1) below high school, 2) high school degree, 3) bachelor degree and 4) graduate degree coded as 1, 2, 3, and 4 respectively. The education variable can be dummy coded as four dummy variables. The analysis can be conducted either using a bachelor’s degree (assuming category with the most observations), or “below high school” (ranked lowest), or “graduate school” (ranked highest) as a base category. To consider one of these categories as a base category, excluding the base label in the list of covariates (independent variables) is sufficient. The table below shows how the education variable is coded and can be translated into dummy coding. I am dummy coding “below high school” as “educ1”, high school degree as “educ2”, bachelor degree as “educ3” and graduate degree as “educ4”. It is not clear, however, which is considered as a base in this table below unless we run the analysis.
| expense | age | educ | educ1 | educ2 | educ3 | educ4 |
| 20 | 45 | 4 | 0 | 0 | 0 | 1 |
| 25 | 30 | 3 | 0 | 0 | 1 | 0 |
| 15 | 50 | 2 | 0 | 1 | 0 | 0 |
| 10 | 60 | 1 | 1 | 0 | 0 | 0 |
| 12 | 30 | 2 | 0 | 1 | 0 | 0 |
| 30 | 25 | 4 | 0 | 0 | 0 | 1 |
| 13 | 37 | 2 | 0 | 1 | 0 | 0 |
| 15 | 48 | 1 | 1 | 0 | 0 | 0 |
| 15 | 70 | 3 | 0 | 0 | 1 | 0 |
| 10 | 19 | 2 | 0 | 1 | 0 | 0 |
| 15 | 21 | 3 | 0 | 0 | 1 | 0 |
| 18 | 25 | 4 | 0 | 0 | 0 | 1 |
In Stata, the above table can be created using the code below. for example, the third line of code below is asking Stata to generate a dummy variable “educ3” with a value of 1 if the variable “educ” has a value of 3, and 0 otherwise. A similar interpretation can be done for the rest of the codes below.
gen educ1 = educ == 1gen educ2 = educ == 2gen educ3 = educ == 3gen educ4 = educ == 4
To know which category is selected as a base level, I am demonstrating a few lines of codes below with an explanation. I am using ordinary least square (OLS) regression as my dependent variable is continuous in nature. Three lines of codes below run three OLS assuming base as educ1, educ3, and educ4 respectively. Note that base categories are excluded (omitted) from the covariates list. The coefficients of the OLS regressions below are interpreted with reference to their respective base categories.
regress expense educ2 educ3 educ4regress expense educ1 educ2 educ4regress expense educ1 educ2 educ3
Another approach to code categorical variable, in a way that is similar to dummy coding, is effect coding. Analysis can be conducted using both dummy coding and effect coding and results are the same in both cases. So, dummy coding and effect coding can be used as an alternative to each other. However, in effect coding, dummy variables can be restricted to sum to zero for the alternative interpretation of coefficients. This is also called as “Alternative Parameterization” of dummy variables. The restriction shifts the reference distribution from one of the omitted categories’ mean to the overall population mean whereas keeping the same base category. The interpretation of dummy variables in effect coding is different in comparison to dummy coding.
There are two steps in effect coding. The first step is to create dummy variables for all categories of a variable as we have done above. Copying the exact code from above and running in Stata will do the job. So, I am jumping straight into the second step and demonstrating code to use in Stata. The second step is to subtract the base category from the rest of the categories to create effect-coded dummy variables. I have demonstrated effect coding considering “below high school” as a base level. The same principle can be applied to change the base level according to the interest of the researcher. However, it requires modifications in the codes I have demonstrated below.
/* Effect Coding in STATA: */replace educ2 = educ2 - educ1replace educ3 = educ3 - educ1replace educ4 = educ4 - educ1
Effect coded dummy variables (educ2, educ3, and educ4) of education look different than dummy coded variables above. However, educ1 looks the same as above because we consider educ1 as a base and is not affected by effect coding. However, base categories affect how other variables code. The table below shows the effect coding of education variables.
| expense | age | educ | educ1 | educ2 | educ3 | educ4 |
| 20 | 45 | 4 | 0 | 0 | 0 | 1 |
| 25 | 30 | 3 | 0 | 0 | 1 | 0 |
| 15 | 50 | 2 | 0 | 1 | 0 | 0 |
| 10 | 60 | 1 | 1 | -1 | -1 | -1 |
| 12 | 30 | 2 | 0 | 1 | 0 | 0 |
| 30 | 25 | 4 | 0 | 0 | 0 | 1 |
| 13 | 37 | 2 | 0 | 1 | 0 | 0 |
| 15 | 48 | 1 | 1 | -1 | -1 | -1 |
| 15 | 70 | 3 | 0 | 0 | 1 | 0 |
| 10 | 19 | 1 | 1 | -1 | -1 | -1 |
| 15 | 21 | 3 | 0 | 0 | 1 | 0 |
| 18 | 25 | 4 | 0 | 0 | 0 | 1 |

The interpretation of dummy coded variables and effect-coded variables are different. The overall means for categories 1, 2,3, and 4 should be interpreted as follows. I have presented mean calculation side by side for easier understanding:
Let’s consider the above regression with educ1 as base levels for regressions with dummy coding and effect coding. Age is excluded in regression for simplicity. The regression equation is as follow:
expense = beta1 + beta2*educ2 + beta3*educ3 + beta4*educ4 + error
Note that beta1 is an intercept of the regression and i is for an individual.
| Null Hypothesis for Dummy Coding | Null Hypothesis for Effect Coding |
|---|---|
| Ho: the means of categories 2, 3, and 4 are different from reference group is Ho: beta2 = 0 Ho: beta3 = 0 Ho: beta4 = 0 | Ho: the means of categories 2, 3, and 4 are different from the population mean: Ho: beta2 = 0 Ho: beta3 = 0 Ho: beta4 = 0 |
| Group Mean Interpretation for Dummy Coding | Group Mean Interpretation for Effect Coding |
|---|---|
| Category Means: E[educ1] = beta1 E[educ2] = beta1 + beta2 E[educ3] = beta1 + beta3 E[educ4] = beta1 + beta4 | Here, beta1 is the overall mean of education and beta2, beta3 and beta4 are mean difference from overall mean for educ2, educ3 and educ4. So, category Means: E[educ1] = beta1 – beta2 – beta3 – beta4 E[educ2] = beta1 + beta2 E[educ3] = beta1 + beta3 E[educ4] = beta1 + beta4 |