Login

Binomial Logistic Regression Analysis using Stata

Introduction

A binomial logistic regression is used to predict a dichotomous dependent variable based on one or more continuous or nominal independent variables. It is the most common type of logistic regression and is often simply referred to as logistic regression. In Stata they refer to binary outcomes when considering the binomial logistic regression. It many ways a binomial logistic regression can be considered as a multiple linear regression, but for a dichotomous rather than a continuous dependent variable.

For example, you could use a binomial logistic regression to understand whether dropout of first-time marathon runners (i.e., failure to finish the race) can be predicted from the duration of training performed, age, and whether participants ran for a charity. Dropout is the dichotomous dependent variable (i.e., "completed" or "dropped out"). Duration of training (in months), age (in years) and charity ("yes" or "no") are the independent variables. Another example where you could use a binomial logistic regression is to understand whether the premature failure of a new type of light bulb (i.e., before its one year warranty) can be predicted from the total duration the light is on for, the number of times the light is switched on and off, and the temperature of the ambient air. In this case, premature failure is the dichotomous dependent variable (i.e., the light bulb fails within its one year warranty: "yes" or "no"). The other three variables used to predict the light bulb failure are all continuous independent variables: the total duration the light is on for (in minutes), the number of times the light is switched on and off and the ambient air temperature (in °C).

This "quick start" guide shows you how to carry out a binomial logistic regression using Stata, as well as how to interpret and report the results from this test. However, before we introduce you to this procedure, you need to understand the different assumptions that your data must meet in order for binomial logistic regression to give you a valid result. We discuss these assumptions next.

Note: We do not currently have a premium version of this guide in the subscription part of our website. If you would like us to add a premium version of this guide, please contact us.

Stata

Assumptions

There are six assumptions that underpin binomial logistic regression. If any of these six assumptions are not met, you might not be able to analyse your data using a binomial logistic regression because you might not get a valid result. Since assumptions #1 and #2 relate to your choice of variables, they cannot be tested for using Stata. However, you should decide whether your study meets these assumptions before moving on.

Fortunately, you can check assumptions #3, #4, #5 and #6 using Stata. Do not be surprised if your data fails one or more of these assumptions since this is fairly typical when working with real-world data rather than textbook examples, which often only show you how to carry out a binomial logistic regression when everything goes well. However, don’t worry because even when your data fails certain assumptions, there is often a solution to overcome this (e.g., transforming your data or using another statistical test instead). Just remember that if you do not check that you data meets these assumptions or you test for them incorrectly, the results you get when running a binomial logistic regression might not be valid.

In practice, checking for assumptions #3, #4, #5 and #6 will probably take up most of your time when carrying out a binomial logistic regression. However, it is not a difficult task, and Stata provides all the tools you need to do this.

In the section, Test Procedure in Stata, we illustrate the Stata procedure required to perform a binomial logistic regression assuming that no assumptions have been violated. First, we set out the example we use to explain the binomial logistic regression procedure in Stata.

Stata

Example

A teacher wanted to understand whether the number of hours students' spent revising predicted success in their final year exams. They also questioned whether gender would influence exam success (although they didn't expect that it would). Therefore, the teacher recruited 189 students who were about to undertake their final year exams. The teacher had the students estimate the numbers of hours they spent revising and record their gender. He then gained their final year exam marks to discover whether they passed or failed the exam. In order to understand whether the number of hours of study had an effect on passing the exam, the teacher ran a binomial logistic regression. Therefore, in this example, the dichotomous dependent variable is pass, which has two categories: "passed" and "failed". The number of hours of study was a continuous independent variable, hours (in hours), and the gender of a participant was a dichotomous independent variable, gender, with two categories: "Male" and "Female".

Note: The example and data used for this guide are fictitious. We have just created them for the purposes of this guide.

Stata

Setup in Stata

In Stata, we created three variables: (1) pass, which is coded "1" for those who passed the exam and "0" for those who did not pass the exam (i.e., the dependent variable); (2) hours, which is the number of hours studied; and (3) gender, which is the participant's gender (i.e., the last two are the independent variables).

After creating these three variables, we entered the scores for each into the three columns of the Data Editor (Edit) spreadsheet, as shown below:

Data editor for binomial logistic regression in Stata

Published with written permission from StataCorp LP.

Stata

Test Procedure in Stata

In this section, we show you how to analyze your data using a binomial logistic regression in Stata when the six assumptions in the previous section, Assumptions, have not been violated. You can carry out binomial logistic regression using code or Stata's graphical user interface (GUI). After you have carried out your analysis, we show you how to interpret your results. First, choose whether you want to use code or Stata's graphical user interface (GUI).


Code

The code to carry out a binomial logistic regression on your data takes the form:

logistic DependentVariable IndependentVariable#1 IndependentVariable#2 IndependentVariable#3 IndependentVariable#4

This code is entered into the Command box below:

Command box in Stata

Using our example where the dependent variable is pass and the two independent variables are hours and gender, the required code would be:

logistic pass hours i.gender

Note: You'll see from the code above that continuous independent variables are simply entered "as is", whilst categorical independent variables have the prefix "i" (e.g., hours for hours, since this is a continuous independent variable, but i.gender for gender, since this is a categorical independent variable).

Therefore, enter the code, logistic pass hours i.gender, and press the "Return/Enter" key on your keyboard.

Command box for binomial logistic regression in Stata

You can see the Stata output that will be produced here.


Graphical User Interface (GUI)

The six steps required to carry out binomial logistic regression in Stata are shown below:

  1. Click Statistics > Binary outcomes > Logistic regression, reporting odds ratios on the main menu, as shown below:
    Binomial logistic regression menu in Stata

    Published with written permission from StataCorp LP.


    You will be presented with the logistic - Logistic regression, reporting odds ratios dialogue box, as shown below:
    Binomial logistic regression dialogue box in Stata

    Published with written permission from StataCorp LP.

  2. Select the dependent variable, pass, from the Dependent variable: drop-down box, and select the continuous independent variable, hours, from the Independent variables: drop-down box, using the relevant Drop-down buttons. You will be presented with the dialogue box below:
    Binomial logistic regression dialogue box in Stata with example

    Published with written permission from StataCorp LP.

  3. Click on the Three dot button. You will be presented with the Create varlist with factor or time-series variables dialogue box, as shown below:
    Binomial logistic regression dialogue box in Stata for factor variables with example

    Published with written permission from StataCorp LP.

  4. Leave Factor variable selected in the –Type of variable– area. Next, in the –Add factor variable– area, leave Main effect selected in the Specification: drop-down box. Now, select gender in the Variables drop-down box using the Drop-down button. Finally, click on the Add to varlist button. You will be presented with the following dialogue box where the categorical independent variable, i.gender, has been entered into the Varlist: box:
    Adding factor variables in the binomial logistic regression procedure in Stata

    Published with written permission from StataCorp LP.

  5. Click on the OK button. You will be returned to the logistic - Logistic regression, reporting odds ratios dialogue box, but with the categorical independent variable, i.gender, now also entered into the Independent variables: box, as shown below:
    Binomial logistic regression dialogue box in Stata with completed example

    Published with written permission from StataCorp LP.

  6. Click on the OK button. This will generate the output.
Stata

Output of the binomial logistic regression in Stata

The output below is only a fraction of the options that you have in Stata to analyse your data, assuming that your data passed all the assumptions (e.g., there were no significant influential points), which we explained earlier in the Assumptions section. However, the following output will present the results needed to ascertain whether the independent variables statistically significantly predict the passing of a final year exam. The results are presented under the "Logistic Regression" header, as shown below:

Output of the binomial logistic regression procedure in Stata

Published with written permission from StataCorp LP.

You can determine whether gender and hours spent revising statistically significantly predicted passing a final year exam by consulting the "P>|z|" column for the "1.gender" and "hours" rows, respectively. The "P>|z|" column contains the p-value for each coefficient and the constant (both expressed as odds ratios). You can see that hours spent revising was statistically significant (i.e., p = .001), but gender was not statistically significant (i.e., p = .968).

Stata

Reporting the output of a binomial logistic regression

When you report the output of your binomial logistic regression, it is good practice to include:

You could write up the results as follows:

  • General

A binomial logistic regression was run to understand the effects of the number of hours of training and gender on the success of passing an exam. Time spent revising for the exam statistically significantly predicted exam success (p = .001), but gender did not (p = .968).

1