Using Statas Margins Command Predicted Values Predicted Probabilities
Using Stata’s Margins Command Predicted Values, Predicted Probabilities, and Graphs A Very Practical (Not Theoretical) Guide
Outline • Factor Variables • Margins Command Possibilities • Predicted Values • Predicted Probabilities • Graphs
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 indepvar 1 indepvar 2 • Type… • reg depvar i. indepvar 1 c. indepvar 2 • This tells Stata that indepvar 1 is a categorical variable and to treat it as such • And that indepvar 2 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!
Factor Variables—Menu
Factor Variables—Syntax Stata command indicating a linear regression reg Marital. Int 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.
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?
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.
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(15. 1. 70 "This bar is", place(e) size(small)) text(15. 05. 70 "too low", place(e) size(small))
Graphing Interaction Terms • reg Marital. Int age ib(3). race educ sibs i. cohab i. prevmar c. age#c. educ
Graphing Interaction Terms
Graphing Interaction Terms This is the categorical variable This is the continuous variable. Specifiy the values you want to get the predicted values in
Graphs
Now do it with syntax • Regression reg Marital. Int c. age ib(3). race c. educ c. sibs i. cohab 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 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(Prev. Mar->Marital Interaction Depends on Pre. Mar Cohabitation) Simple Slopes margins, dydx(cohab) at(prevmar=(0/1)) vsquish
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 Marital. Dummy age ib(3). race educ sibs i. cohab i. prevmar • margins race, atmeans vsquish • marginsplot, noci recast(bar) • Note: Marital. Dummy = 0 if below median on marital interaction, 1 if above median on
Predicted Probabilities What do these numbers mean?
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
Predicted Probabilities • Graph Those Probabilities! • marginsplot, noci recast(bar)
Predicted Probabilities—Interaction Term • logit Marital. Dummy age ib(3). race educ sibs i. cohab i. prevmar c. age#i. prevmar
Predicted Probabilities—Interaction Term • margins prevmar, at(age=(20(10)60)) atmeans vsquish
Predicted Probabilities—Interaction Term • marginsplot, noci xtitle(Age) ytitle(Predicted Prob. of High Marital Interaction) title(Age->Marital Interaction Depends on If Previously Married)
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
- Slides: 21