Download presentation
Presentation is loading. Please wait.
1
Using Stata’s Margins Command
Predicted Values, Predicted Probabilities, and Graphs A Very Practical (Not Theoretical) Guide
2
Outline Factor Variables Margins Command Possibilities
Predicted Values Predicted Probabilities Graphs
3
Factor Variables--What Are They and Why Do They Matter?
Factor variables are Stata-specific notation for identifying categorical and continuous INDEPENDENT variables Instead of typing… reg depvar indepvar1 indepvar2 Type… reg depvar i.indepvar1 c.indepvar2 This tells Stata that indepvar1 is a categorical variable and to treat it as such And that indepvar2 is a continuous variable This means you don’t have to create variables anymore! No need to create dummies for race, marital status, religious affiliation, etc. As we’ll see momentarily, it also means you don’t need to create interaction variables either. Stata will do both of those things for you!
4
Factor Variables—Menu
5
Factor Variables—Syntax
Stata command indicating a linear regression reg MaritalInt c.age i.race c.educ c.sibs i.cohab i.prevmar Dependent Variable Independent Variables (’c.’ indicates a continuous variable while ’i.’ indicates a categorical one.
6
The Margins Command Designed to provide predicted values of Y for a particular combination of your x’s, along with many other things. Say you have the following regression--> You’re trying to predict marital interaction. But how do I make sense of the race differences?
7
The Margins Command The margins command to the rescue!
margins race, atmeans vsquish That is, the model predicts that Asians have the highest level of marital interaction, followed by Hispanics and Whites.
8
The Margins Command Now you can graph this
margins, noci Or make it fancier (and a bar plot) marginsplot, noci recast(bar) title("Adjusted Predictions of Marital Interaction, by Race (CREATE Wave 1)") ///ytitle(Predicted Marital Interaction) xtitle("") text( "This bar is", place(e) size(small)) text( "too low", place(e) size(small))
9
Graphing Interaction Terms
reg MaritalInt age ib(3).race educ sibs i.cohab i.prevmar c.age#i.prevmar c.age#c.educ
10
Graphing Interaction Terms
11
Graphing Interaction Terms
This is the categorical variable This is the continuous variable. Specifiy the values you want to get the predicted values in the box below
12
Graphs
13
Now do it with syntax Regression
reg MaritalInt c.age ib(3).race c.educ c.sibs i.cohab i.prevmar c.age#i.prevmar c.age#c.educ i.prevmar#i.cohab Continuous X categorical interaction margins prevmar, at(age=(20(10)60)) atmeans vsquish maginsplot, noci marginsplot, noci ytitle(Predicted Marital Interaction) xtitle(Age) ytitle(Pred. Marital Interaction) title(Age->Marital Interaction Depends on If Previously Married) Continuous X continuous interaction margins, at(age=(20(10)60) educ=(0/3)) atmeans vsquish marginsplot, noci marginsplot, noci ytitle(Predicted Marital Interaction) xtitle(Age) ytitle(Pred. Marital Interaction) title(Age->Marital Interaction Does Not Depend on Education) Categorical X Categorical margins cohab, at(prevmar=(0/1)) atmeans vsquish marginsplot, noci ytitle(Predicted Marital Interaction) xtitle(Previously Married) title(PrevMar->Marital Interaction Depends on PreMar Cohabitation) Simple Slopes margins, dydx(cohab) at(prevmar=(0/1)) vsquish
14
Predicted Probabilities
Same process, virtually identical syntax, just trade out `reg’ for `logit’. For menus, it’s much the same except you select ‘Statistics->Binary Outcomes->Logistic regression, reporting coefficients’. I’ll forgo showing the menus for now. Syntax logit MaritalDummy age ib(3).race educ sibs i.cohab i.prevmar margins race, atmeans vsquish marginsplot, noci recast(bar) Note: MaritalDummy = 0 if below median on marital interaction, 1 if above median on
15
Predicted Probabilities
What do these numbers mean?
16
Predicted Probabilities
Translate the log-odds into predicted probabilites (the probability that Other Race, Black, Asian, Hispanic, or White = 1) with the margins command margins race, atmeans vsquish
17
Predicted Probabilities
Graph Those Probabilities! marginsplot, noci recast(bar)
18
Predicted Probabilities—Interaction Term
logit MaritalDummy age ib(3).race educ sibs i.cohab i.prevmar c.age#i.prevmar
19
Predicted Probabilities—Interaction Term
margins prevmar, at(age=(20(10)60)) atmeans vsquish
20
Predicted Probabilities—Interaction Term
marginsplot, noci xtitle(Age) ytitle(Predicted Prob. of High Marital Interaction) title(Age->Marital Interaction Depends on If Previously Married)
21
Conclusion The margins command is a compelling tool for helping us visualize and understand our data, all while saving us time The use of factor variables eliminates the need to create interaction or dummy variables We can quickly and easily translate our results into meaningful units, ensuring maximum comprehension of our data The marginsplot command makes it simple and quick to create graphs
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.