• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
The Analysis Factor

The Analysis Factor

Statistical Consulting, Resources, and Statistics Workshops for Researchers

  • Home
  • Our Programs
    • Membership
    • Online Workshops
    • Free Webinars
    • Consulting Services
  • About
    • Our Team
    • Our Core Values
    • Our Privacy Policy
    • Employment
    • Collaborate with Us
  • Statistical Resources
  • Contact
  • Blog
  • Login

When Dummy Codes are Backwards, Your Stat Software may be Messing With You

by Karen Grace-Martin 2 Comments

One of the tricky parts about dummy coded (0/1) variables is keeping track of what’s a 0 and what’s a 1.

This is made particularly tricky because sometimes your software switches them on you.

Here’s one example in a question I received recently.  The context was a Linear Mixed Model, but this can happen in other procedures as well.

I dummy code my categorical variables “0” or “1” but for some reason in the fixed effects table the variable with code “0” has a coefficient and the variable coded “1” has the coefficient “0” and and considered redundant. I always thought that the fixed effects table is similar to a regression table in that you should be able to calculate the estimates because you are given coefficients. but how can i do this when the dummy variables coded with a “0” have a coefficient and those coded “1” don’t. when i use the equation, won’t this variable always be zero.???

This person is rightfully confused.  There’s no indication of what software was involved, but I’ve seen it happen in different software packages and in different procedures.

In SAS proc glm, when you specify a predictor as categorical in the CLASS statement, it will automatically dummy code it for you in the parameter estimates table (the regression coefficients). The default reference category–what GLM will code as 0–is the highest value.  This works just fine if your values are coded 1, 2, and 3.  But if you’ve dummy coded them already, it’s switching them on you.

Likewise, in both SPSS mixed and GLM, the default is to make the one that comes last alphabetically the reference group, 0.  So if your data are M and F, M will be the reference group.  But if the data are 0 and 1, 1 comes after 0 alphabetically, and 1 becomes the reference group.  The new 0.

You may therefore be tempted to just put it in as a covariate–i.e., don’t tell your software it’s categorical.  This usually works, but neither package will then give you means (lsmeans in SAS and EMMeans in SPSS) for that variable.  Since interpreteing means is often much, much more intuitive, you have to define it as categorical.

You have to be careful in logistic regression as well.  In binary logistic regression, the outcome variable is coded 0/1.

Not too long ago I made a big mistake working on a client’s data set, which luckily I caught when the results didn’t make sense.

The default in SPSS binary logistic regression is to model the odds that Y=1. I knew that, and assumed it was the same in GEE.  Not so.  So the model wasn’t wrong, per se.  But I was interpreting everything backwards.  Funny, none of the hypotheses were supported when the analysis was backward.

The lesson I learned?  Know thy software defaults.

There are a lot of them.  That’s one reason I say it really doesn’t generally matter much which stat software you use, as long as the one you’re using can do what you need.

But whatever you choose, know it really, really well.

Make the syntax manual your best friend in crime data analysis.

[For the record, I also recommend all researchers be able to use at least two stat software packages.  Follow that link, if you’re wondering why].


Bookmark and Share

If you want to learn more about interpreting coefficients, in one of my first webinars I literally went through the output of a model with both categorical and continuous predictors (and an interaction), and we went step-by-step through how to read the coefficients.

You can download it here: Interpreting Linear Regression Coefficients: A Walk Through Output.  It’s free.<https://www.theanalysisfactor.com/interpreting-linear-regression-parameters-a-walk-through-output/” rel=”nofollow”>

Interpreting Linear Regression Coefficients: A Walk Through Output
Learn the approach for understanding coefficients in that regression as we walk through output of a model that includes numerical and categorical predictors and an interaction.

Tagged With: dummy coding, Reference Group

Related Posts

  • Dummy Coding in SPSS GLM–More on Fixed Factors, Covariates, and Reference Groups, Part 1
  • SPSS GLM or Regression? When to use each
  • SPSS GLM: Choosing Fixed Factors and Covariates
  • Centering a Covariate to Improve Interpretability

Reader Interactions

Comments

  1. Rajiv Kumar says

    November 5, 2015 at 8:59 pm

    Can you show with an example how to put this variable in the equation?

    Reply
  2. ali says

    September 17, 2015 at 2:59 am

    Hi

    Thank you for sharing your knowledge. The article was very helpful for me. I have another question which is related to the next step, Interpreting and writing the regression equation from outputs. As you know, software will determine the estimations for each variables. If we have a categorical variable (for example with 4 levels ), we’ll have three coefficients (one level will be considered as a reference level). How should we write the regression equation? is there a way to merge the coefficients related to each levels of categorical variable??

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Please note that, due to the large number of comments submitted, any questions on problems related to a personal study/project will not be answered. We suggest joining Statistically Speaking, where you have access to a private forum and more resources 24/7.

Primary Sidebar

This Month’s Statistically Speaking Live Training

  • Member Training: Analyzing Pre-Post Data

Upcoming Free Webinars

Poisson and Negative Binomial Regression Models for Count Data

Upcoming Workshops

  • Analyzing Count Data: Poisson, Negative Binomial, and Other Essential Models (Jul 2022)
  • Introduction to Generalized Linear Mixed Models (Jul 2022)

Copyright © 2008–2022 The Analysis Factor, LLC. All rights reserved.
877-272-8096   Contact Us

The Analysis Factor uses cookies to ensure that we give you the best experience of our website. If you continue we assume that you consent to receive cookies on all websites from The Analysis Factor.
Continue Privacy Policy
Privacy & Cookies Policy

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Non-necessary
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
SAVE & ACCEPT