Modeling Binary Variables in STATA
In this guide you will:
Table of contents:
1.0 Should We Use OLS When We Work With Outcomes on a 0-1 Scale?
2.0 Loading and Exploring Sample Data with a Binary Variable
3.0 How to Run a Logistic Regression
4.0 Calculating Marginal Effects
5.0 Comparing Interpretations Between Log-Odds, Odds-Ratios, and AME
6.0 Evaluating Model Fit
7.0 Interactive Activity
- Understand how to model 0-1 outcomes in STATA
- Learn how to code logit models and calculate average marginal effects
Table of contents:
1.0 Should We Use OLS When We Work With Outcomes on a 0-1 Scale?
2.0 Loading and Exploring Sample Data with a Binary Variable
3.0 How to Run a Logistic Regression
4.0 Calculating Marginal Effects
5.0 Comparing Interpretations Between Log-Odds, Odds-Ratios, and AME
6.0 Evaluating Model Fit
7.0 Interactive Activity
1.0 Introduction: Should We Use OLS When We Work With Outcomes on a 0-1 Scale?
You already know how to run a linear regression with ‘regress’ in Stata. So why learn a new command?
Here’s the simple answer: imagine you're trying to predict whether something happens or doesn't; e.g. a woman is employed or she isn't. There's no half outcome. It's a yes/no, 1/0 question.
Regular OLS regression was built to predict numbers that can be anything, income, height, test scores. It was never built to predict something that can be 0 or 1. So when you force it to, weird things happen. It might predict a 130% chance of something happening or a -20% chance. Neither of those means anything is real life, probabilities have to be between 0% and 100%.
The Problem with OLS on Binary Outcomes
Consider the outcome inlf: a woman is either in the labor force (1) or not (0). If we run OLS on this, we get a Linear Probability Model (LPM). The LPM is not wrong, exactly, but it has a fundamental flaw:
- OLS can predict values below 0 or above 1. A probability of 1.3 or -0.2 is not interpretable.
- The relationship between predictors and a binary outcome is rarely linear across the full range. Near the extremes, the effect of a predictor should naturally taper off.
- Standard errors can be unreliable because the error term is heteroskedastic by construction.
Logistic regression solves this by modeling something different - instead of modeling Y directly, it models the probability that Y = 1. And it does so in a way that keeps predictions bounded between 0 and 1 no matter what.
The Logistic Function Explained

Instead of fitting a straight line through Y, logistic regression fits an S shaped curve through the probability of Y = 1. No matter what combination of predictors you feed in, the output is always between 0 and 1.
Think of it this way - as education increases, at some point the probability of labor force participation starts to level off toward 1. And at the other end, even low-education women have some baseline probability of participating. The logistic curve captures this naturally. OLS does not.
2.0 Loading and Exploring Sample Data With a Binary Variable
We will use the mroz dataset from the Wooldridge Stata package.
This is a classic labor economics dataset with 753 married women, tracking whether they participated in the paid labor force in 1975.

Here's the big question we're trying to answer: what makes a married woman more or less likely to work outside the home?
Things like how educated she is, how old she is, how many young kids she has, and how much her husband earns; do any of these actually move the needle on whether she works? Since the answer for each woman is simply “yes she works” or “no she doesnt” this is exactly the kind of yes/no outcome logistic regression is built for.
Installing and Loading in the Data
Before you start, open a new do-file so you can save and rerun this work later
This loads the dataset directly into memory. No need to navigate to a file path.

This loads the dataset directly into memory. No need to navigate to a file path.

Confirming the Binary Outcome
Always verify your outcome variable before running any model. Use describe and codebook to inspect the variable type and value labels:

You should see that inlf takes only the values 0 and 1, confirming it is a proper binary indicator.

Checking the Outcome Split
Use tabulate to see how many women are in and out of the labor force:
Previewing the Predictors
Summarize the key variables we will use as predictors:

3.0 How to Run a Logistic Regression
We use the logit Command to set up a basic logistic regression
The syntax mirrors regress exactly: outcome variable first, then predictors.
Stata
logit inif educ exper kidslt6Run this command. Stata will print an output table that looks like this:

NOTE:
Your output will also show the log-likelihood, number of observations, LR chi2, and Pseudo R-squared above the coefficient table. We will cover model fit in Section 4.
Reading the Output Table
The columns are the same as OLS, with one key difference:
- Coef: the estimated log odds coefficient for each predictor
- Std Err: the standard error of that estimate
- z: the test statistic. This is a z statistic (normal distribution), not a t statistic. For large samples the difference is negligible, but logistic regression uses maximum likelihood estimation, not OLS, so Stata reports z.
- P>|z|: the two sided p value. Interpret exactly the same as in OLS.
- [95% Conf. Interval]: confidence interval for the coefficient.
Log Odds: What the Logit Transformation Does
Logistic regression achieves this by working with the log odds (also called the logit) of the outcome instead of the probability directly.
Here is the intuition:
- A probability of 0.5 corresponds to even odds (1:1), which maps to a log odds of 0.
- A probability above 0.5 gives positive log odds.
- A probability below 0.5 gives negative log odds.
- Log odds range from negative infinity to positive infinity, so a linear model fits naturally.
The model estimates the relationship between predictors and log odds, then converts back to probabilities using the logistic function. This is why the raw coefficients from logit are in log odds units and not directly interpretable as percentage point effects. We will return to this.
How to interpret logit coefficients
The raw coefficients from logit are in log odds units. You cannot interpret the magnitude directly as a percentage point effect. But the signs are immediately meaningful:

NOTE:
Positive coefficient = increases probability of Y=1. Negative coefficient = decreases probability of Y=1. Magnitude is not interpretable without additional steps.
Why would you use one over the other? It comes down to how you want to communicate your results:
- Logit reports raw log odds coefficients.
- Logistic reports odds ratios.
logit vs. logistic! What Changed??
Run the model again using logistic instead of logit:
Stata
logistic inif educ exper kidslt6The underlying model is identical, same data, same estimation, same log-likelihood. The only difference is how Stata displays the results.
- logit shows log odds coefficients. These are directly related to the linear predictor in the model. Useful for comparing models or understanding model structure.
- logistic shows odds ratios, which are exp(coefficient). These are sometimes easier to communicate: "each additional child under 6 reduces the odds of participation to 23% of what they were otherwise." But they are still not probabilities.
- Confidence intervals, z statistics, and p values are identical across both commands.
Choosing between ‘logit’ and ‘logistic’Use logit if you are comparing coefficients across models or reporting in a setting where log odds are standard. Use logistic if your audience is more comfortable with odds ratios. In either case, report marginal effects from margins, dydx(*) for the probability scale interpretation that applied papers use. |
How to read odds ratios:
- OR = 1: no effect
- OR > 1: increases the odds of Y=1
- OR < 1: decreases the odds of Y=1

NOTE: Do not interpret an OR of 1.25 as "education increases the probability by 25%." For probability based interpretation, use marginal effects (Section 4). Odds ratio = e^(coefficient)
4.0 Calculating Marginal Effects
In a logistic regression, the effect of a variable isn't fixed, it changes depending on the person. This is actually the main way logistic regression is different from a regular (linear) regression.
Think of it this way: in a regular regression, one more year of education always adds the same fixed boost to your prediction, no matter who you are. In logistic regression, that's not true. Because the model uses a curve instead of a straight line, that curve is steep in the middle and flat near the edges like a hill that's steep halfway up but flattens out near the top and bottom…
So picture two women. One already has a lot going for her high education, lots of work experience so she's already very likely to be working. She's near the "flat" part near the top of the curve, so one more year of education barely moves her probability, since she's already close to 100%. Now picture a woman right in the middle not particularly likely or unlikely to work. She's on the steep part of the curve, so that same one extra year of education moves her probability a lot more.
So we use : The ‘margins’ command
After running logit, in the previous code line, run the following on a separate line:
The dydx(*) option tells stata to compute the derivative of the predicted probability with respect to each predictor (dy/dx), averaged across all observations. The asterisk means do it for every variable in the model.
Average Marginal Effect (AME): the average of the individual marginal effects calculated at each observation's actual covariate values. It avoids the assumption of hypothetical "average individuals" and respects the real distribution of the data.
Your output will look like this:
Think of it this way: in a regular regression, one more year of education always adds the same fixed boost to your prediction, no matter who you are. In logistic regression, that's not true. Because the model uses a curve instead of a straight line, that curve is steep in the middle and flat near the edges like a hill that's steep halfway up but flattens out near the top and bottom…
So picture two women. One already has a lot going for her high education, lots of work experience so she's already very likely to be working. She's near the "flat" part near the top of the curve, so one more year of education barely moves her probability, since she's already close to 100%. Now picture a woman right in the middle not particularly likely or unlikely to work. She's on the steep part of the curve, so that same one extra year of education moves her probability a lot more.
So we use : The ‘margins’ command
After running logit, in the previous code line, run the following on a separate line:
Stata
margins, dy/dx(*)
The dydx(*) option tells stata to compute the derivative of the predicted probability with respect to each predictor (dy/dx), averaged across all observations. The asterisk means do it for every variable in the model.
Average Marginal Effect (AME): the average of the individual marginal effects calculated at each observation's actual covariate values. It avoids the assumption of hypothetical "average individuals" and respects the real distribution of the data.
Your output will look like this:

Interpreting the marginal effects output

NOTE:
Note: The dy/dx column is now in probability units, not log odds units. These are the numbers you can actually communicate to a non technical audience.
5.0 Comparing Interpretations Between Log-odds, Odds Ratios, and AME
If you had to explain the relationship between education and the probability of labor force participation to a friend with no economics background, which interpretation would you use?
If you refer to the output in the form of Odd’s Ratios that we get from just running the ‘logit’ command, good luck trying to explain what an “increase in the log odds” means in relation to labor force participation! If instead, we ran ‘logistic’, the interpretation of the relationship of our two variables through percentage increase in odds is slightly better, but still quite confusing for people that don’t have a solid grasp of probability and statistics. Average marginal effects offers a much clearer interpretation of the relationship by displaying a percentage point increase.

REMINDER: The AME column (from margins after either command) is the same regardless of which display format you used. The marginal effects are a property of the model, not the display.
6.0 Evaluating the Model Fit
In OLS, R squared tells you the proportion of variance in Y explained by your predictors. Logistic regression does not have a direct equivalent. There are two main tools Stata gives you: Pseudo R squared and the classification table.
Pseudo R-Squared
When you run ‘logit’, Stata automatically reports a Pseudo R squared (McFadden's R squared) in the header above the coefficient table. It is calculated as:
Pseudo R2 = 1 - (log-likelihood of full model / log-likelihood of null model)

| Context matters more than benchmarks: Unlike OLS, logistic regression does not have a universal threshold for what counts as a good fitting model. Focus on whether the coefficients are significant and sensibly signed, and whether the marginal effects are large enough to be practically meaningful. The classification table (below) often tells a more intuitive story. |
| The bottom line on fit: For logistic regression, fit diagnostics are context dependent. A model with a Pseudo R squared of 0.12 and correct classification of 71% might be exactly what you need if the coefficients answer your research question. Do not chase a high Pseudo R squared the way you might chase an OLS R squared. |
7.0 Activity
Now it is your turn. Run the following model in Stata and work through the interpretation questions below.
Stata
* Step 1: Run the model logit inlf educ exper kidslt6 nwifeinc * Step 2: Get the marginal effects margins, dy/dx(*)
Note:
nwifeinc is the wife's non labor income (husband's earnings and other household income, in thousands of dollars). This captures the income effect: if the household already has money coming in, the wife could be less likely to enter the labor force.
Interpretation Questions:
| Part A: Sign and Significance Look at the logit output table. For each predictor:
|
| Part B: Marginal Effects in Plain English From the margins, dydx(*) output:
|
By: Ananya Malhotra