Wednesday, January 13, 2016

Margins Command in Stata

This walks through an example to help explain the margins command in Stata for nonlinear regressions.

I use the psi example (* I was getting confused between the 0.psi and 1.psi in the header and what the coefficeints under Margin in the table were. 

use, clear
logit grade gpa tuce i.psi, nolog
margins psi,  atmeans

1.psi (.4375)  is just average psi (or like average females), and it's just the perecentage of psi or females. and 0.psi is 1 - 1.psi. You can just type summ psi, to get .4375

psi==0 and psi==1 are the probabilities of being psi==0 or psi==1 and the difference (.5632555 - .1067571  ) is the increase in the probability of going from 0 to 1 (where all other variables are held constant at the mean), so
this difference is the same thing as the coefficient on 1.psi ( .4564984  ) after running:
logit grade gpa tuce i.psi, nolog
margins, dydx(*) atmeans

Finally, the delta in psi==0 to psi==1, and dydx@psi at means, will be the same as the marginal effect of that dichotomous variable in a linear regression. Just the standard errors change.
I think that's what I've figured out from all of this so far. Aslo the ucla site was better for me than teh pdf


Person A: 
I am still not clear on the difference between margins, atmeans and margins,dydx atmeans. If I run a mutlivariate regression ( y on x1, x2, and x3) and I want the marginal effect for each x, which command do I use? Do I put my varlist after margins, or ‎inside dydx()?

Person B: 
Margins, at means predicts the probabilities of your dichotomous outcome variable holding all other variables constant at their means. 
Margins, dydx at means will calculate the marginal effect of all your variables at the mean value (so if it's a gnarly function, it will only take the derivative at the center of that function).
You want the second: margins, dydx(michelle's variables) atmeans

Person A: 
So the first (margins, atmeans) tells us what we could expect from the average person in the sample?

Person B: 
Under treatment vs control. Yes.The difference btw those two numbers will equal the dydx estimate.