Margins command in Stata | Johan Osterberg - Product Engineer

Margins command in Stata

June 18, 2019

Following up on the last post on linear regression let's look at a way of visualizing the results to better aid interpretation. For this purpose we will introduce the margins command in order to compute the effects on wage at different levels of schooling, across race groups. Let's start by loading up the nlsw88 dataset again.

sysuse nlsw88, clear
margins race, at(grade=(8 10 12 14 16 18))

What this command does is that it predicts the weekly wage across wage groups at different fixed levels of the variable grade. In other words, it calculates the expected weekly wage for a white/black/other woman with 8-18 years of education. To visualize, let's plot the values by using the marginsplot command. This will reate a line chart of predicted wages at the given intervals by grade over race group:

marginsplot 

Margins plot


Profile picture

Written by Johan Osterberg who lives and works in Gothenburg, Sweden as a developer specialized in e-commerce. Connect with me on Linkedin

2025 © Johan Osterberg