Regression Postestimation Commands in Stata: margins, pt. 1

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
it's code in the D to give the keyboard a punch Santos door lead and a break for someone shot collate tabulate process and screen program readout progressed to the mean it's homeboys cage coded put program in right hey guys welcome back to my video series on using Stata for statistical analysis we've been working on a set of videos looking at regression analysis and this video fits right into that section pretty nicely it's part of our post estimation commands once we get our model established and estimated the fun begins where we start looking at results of our model so today we're going to look at a very simple example of using margins and margins plot those two commands go hand in hand for this series of videos I've been using the General Social Survey our dependent variable is occupational prestige this is a scale that ranges from approximately 17 to 86 our primary deep independent variable is going to be number of years of education so let's go ahead and run our first regression model we're simply inline-6 going to regress the occupational prestige measure on the education measure and these are for data from 2010 what I'm going to do is highlight this line by clicking on the 6 and then I'm going to come up here into the bar and and click on the execute selection command there's our results very typical regression results let's go right to the coefficient we can see that our regression coefficient for education is approximately 2.3 this tells us that on average as education increases by a year occupational prestige increases by approximately 2.3 we get a t statistic and a confidence interval now what the margins command is going to do is basically look at our model use this model to give us the expected value for this particular dependent variable which is occupational prestige so let's go ahead and run that so here we get our result of margins it's not that impressive but we learned that based on this model our average predicted value is approximately fifty three point five we can also use margins plot right after this command to get a visualization and if I click on line nine and execute we'll get our first visualization now this is not particularly impressive but literally it's taking the information from this table it's taking the mean it's plotting it as the point in the middle and then we have our 95% confidence interval so we have those confidence bars going around it so this is kind of interesting but margins has much more to it we can hold a variable constant at a particular value for example in line 11 I'm going to go ahead and issue the margins command and come up with the margins for when education is equal to ten years of education let me close this graphic and we'll go ahead and look at that we can see now we get a value of 35 well it's lower than the forty-three and it should be because we know that as education goes up on average occupational prestige goes up and conversely for lower levels of education occupational prestige is lower as well margins we could also visualize this and we could get the confidence interval around this particular value but you could now you can start thinking more expansively well what if we could use margins to look at make predictions look at our predictions our y hats for different values of education for example let them in line twelve when I execute this line I'm going to get the margins for for people who have ten years of education and people with fifteen years of education and there's our results so let's look at this margins table and see if we can make sense of what's going on we've we've constrained education to be fixed at a value of 10 and a value of 15 what the margins command will do is use the value of 10 for everybody in our sample and make a predicted value of their occupational prestige and then produce an average of that and that's where we get our roughly 35 when we constrain education to be equal to 15 it takes that same set of people and now says what if their education was 15 calculates the average IQ calculate say Y hat or predicted value and then average ISM and we get our marginal value of approximately 47 if I take those two values and calculate the difference of them and I'm going to use the display command to do this in line 14 I'm just going to calculate the arithmetic difference between these two margins we can see that they're approximately that the occupational prestige is approximately 11 different across these two values now we also know that our beta hat sub 1 our coefficient for education is approximately 2.3 and that there's a five-year difference here between 10 and 15 years of education so I should be able to capture or reconstruct this difference by looking at my regression coefficient times 5 I can get to that regression coefficient by using that underscore B and then those square brackets in the name of the variable so this will go ahead and use the use the beta hat sub 1 that's calculating my regression model and sure enough I get the exact same value so now you can start seeing that you know this becomes a very powerful tool if I'm interested in comparing people that have comparing marginal values for 10 years of Education to 15 I'm able to hold those factors constant set them at these values and compare them but I can do even more than that let's go down there and look at the code in line 17 through line 20 so 17 I'm just going to go rerun my model then I'm going to issue my margins command and now I'm using an option called at and what I'm going to do it's the same as the act command before but I'm going to put in more values my education variable in this particular data set ranges from 0 to 20 so I'm going to use the static convention to start at zero increment by 1 and n to 20 so this will calculate the margins for people with it for setting education equal to 0 setting education equal to 1 equal to 2 and so forth up through 20 then my margins plot instead of plotting a single margins with a confidence interval we'll plot 21 margins with their confidence intervals let's go ahead and see what that looks like so there's my margins table now the margins table certainly can be interpreted but it's really just a listing of the data and I don't spend a lot of time looking at it I go right to the visualization the only difference between this visualization and the one before is I'm adding an option to give this a name so I'm going to call this margins 1 here's the default plot that we get so what we're getting is in essence a scatter plot with the points for each of the margins plotted and then confidence bars for our 95% confidence intervals this is not a great graphic I mean it's certainly fine for me to examine it quickly and get a sense of what's going on but I want to show you two more options that make this graphic much stronger in line 20 I'm issuing the same margins plot command but now I'm adding an option called recast so I'm taking the default margins plot which is a scatter plot and saying let's make it a line plot it's going to get rid of those big points in the middle but leave the line and then I'm going to use the recast CI option where CI is for confidence interval and I'm going to use the AR area option to turn this into a shaded area instead of these individual lines and I'm going to call this graphic margins to and I can put these side-by-side you can see that these graphics are identical to one another except for the way the data are visualized but they contain the same information I happen to like the one on the right a lot better than the one on the left but for a quick quick glance at the data the one on the left is certainly sufficient the last problem I want to look at here is to show you really some of the one of the more powerful features of margins when we have quadratic terms now I'm going to run a new regression I'm going to regress regress the occupational prestige variable on to the education variable and an interaction variable of education with itself so what we're saying here is that while we know that education has an additive effect to relationship with occupational prestige is there a multiplicative one as well that is we really have to specify that the rate of change changes by level of education so I'm using factor notation here which I've covered in another video and to calculate this regression I just do C dot e-d-u C the C informs data that this is a continuous variable pound sign pound sign so this is going to be create a main effect and an interaction effect and then the variable I'm interacting it with which is C educ let's go ahead and take a look at our regression output we can see that our education variable has a large enough T statistic to be statistically significant we can see that our interaction term also is statistically significant and positive so let's go ahead and calculate our margins for each year of education the way I did before and let's visualize it in the same way that I did before and see what we get I'm not going to spend time looking at the numbers in the table I'll go right to the visualization and sure enough we find we find that there seems to be an interaction effect here where for lower levels of education there's very little increase in occupational prestige with each year of increase but once we get to you know roughly ten years of education maybe high school 12 years of education that each additional year of education confers greater and greater amounts of occupational prestige we can also see very quickly that our best estimates tend to be in the middle of the distribution of years of education not surprising given that the average number of years of education is close to 12 years but we also can understand that our worse estimates are down at the low levels of education because there's very few people down there estimates are inherently weaker because we have few people with 0 1 2 3 4 years of education I hope this video helps get you going on margins we're going to have other videos that look at some of the more advanced features and and more advanced problems one thing you'll really like about margins is when we start looking at nonlinear relationships with logistic regression margins really keeps tracks of those interaction terms and calculates the marginal effects perfectly as usual if you have any questions please let me know and I'll do my best stands for them in the D to give the keyboard a punch to lead and a break for some buckshot collate tabulate process and screen program readout progressed to the mean and it's old boys cage coded book program in writing no
Info
Channel: Alan Neustadtl
Views: 31,263
Rating: 4.9818182 out of 5
Keywords: Stata, socy699c, socy602, Statistics (Field Of Study), regression, postestimation, margins, marginsplot, tutorial, GSS, General Social Survey
Id: tJFzwFOKEcc
Channel Id: undefined
Length: 12min 5sec (725 seconds)
Published: Wed Nov 27 2013
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.