[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

From |
Jeph Herrin <[email protected]> |

To |
[email protected] |

Subject |
Re: st: -margins- vs -adjust- |

Date |
Wed, 04 Nov 2009 22:02:29 -0500 |

Thank you for the clarifications, which are very helpful. I apologize for any confusion that arose from my referring to predictive margins as marginal effects; what I did not see was a way to get predictive margins from -margins- without using factor notation. cheers, Jeph Jeff Pitblado, StataCorp LP wrote:

Jeph Herrin <[email protected]> noticed that -adjust- has been superseeded by the -margins- command in Stata 11:After getting an error with -adjust-, I discovered that it had been deprecated in version 11. The online help says: "adjust has been superseded by margins. margins can do everything that adjust did and more." However, as far as I can tell, this is not the case. I could use -adjust- with models that did not include factor variables; however, with -margins- there seems to be no option to find marginal effects for independent variables that are not i.vars. Is this true? Or is there a way to fool -margins- into working with non-factor variables? Apologies if this has come up before, I could not find anything on the list or FAQ. If it is true, this is a complete nusiance. I do not normally include dichotomous variables as factor variables, and am not interested in starting now. Moreover, I have estimation results from -xtmelogit- models that ran for days; am I going to have to re-estimate with -i.female- instead of -female- to get marginal effects? (-adjust- gives errors). That, or calculate my own marginal effects from scratch.It isn't clear what Jeph means by "marginal effects" related to the -adjust- command. Martin Weiss <[email protected]> gave two examples using the -dydx()- option of -margins- to compute marginal effects using a -logit- model fit. The first used the 'i.' operator on a factor variable (named 'race') in the -logit- model fit, the second treated 'race' as a standard variable. Peter Lachenbruch <[email protected]> noted that Martin's examples were fitting two different models. Note -margins- computed the marginal effect of 'race' differently, depending of whether it was specfied as a factor variable (with the 'i.' operator) or not. Jeph replied to Martin's post using a regular variable in the -margins- varlist, such as . margins smoke factor smoke not found in e(b) r(111); The variables in -margins- varlist specification are interpreted as factor variables, identifying the predictive margins of interest. Thus the above example is requesting the predictive margins for the -smoke- factor variable. I imagine that Jeph might be referring to the -by()- option of -adjust-. If that is the case, then we just need to translate between -adjust- and -margins- syntax. Here are a few examples based on Martin's first post to this thread (I've included the Stata output from these examples following my signature): . webuse lbw . logit low age lwt race smoke ptl ht ui Compute the mean prediction, Pr(low), over each level of smoking status, adjusting for the mean of each predictor within smoking status: . adjust, pr by(smoke) translates to . margins, over(smoke) at((means) *) Compute the mean prediction, Pr(low), over each level of smoking status, adjusting for the overall mean of each predictor (except smoking status): . adjust age lwt race ptl ht ui, pr by(smoke) translates to . margins, over(smoke) at((omeans) * (asobserved) smoke) Note that Jeph will get the same results from -margins- when the -logit- fit treated -smoke- (and -race-) as factor variables. Verkuilen, Jay <[email protected]> posted an example where -adjust- allows variables in the -by()- option that were not in the model fit. The -over()- option of -margins- allows this too. Philip Ender <[email protected]> used Jay's -logit- model fit to show that -margins- with the -if- clause produces similar point and standard error estimates, but that the confidence intervals are different. The -pr- confidence intervals from -adjust- are computed by transforming the end-points of the CI limits from the linear prediction.-margins- computes the CI limits using the normal approximation is valid.--Jeff [email protected] *** Stata output from the preceeding examples: . webuse lbw, clear (Hosmer & Lemeshow data) . logit low age lwt race smoke ptl ht uiIteration 0: log likelihood = -117.336Iteration 1: log likelihood = -102.61679Iteration 2: log likelihood = -102.17476Iteration 3: log likelihood = -102.17373Iteration 4: log likelihood = -102.17373Logistic regression Number of obs = 189 LR chi2(7) = 30.32 Prob > chi2 = 0.0001 Log likelihood = -102.17373 Pseudo R2 = 0.1292 ------------------------------------------------------------------------------ low | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- age | -.0332327 .0357713 -0.93 0.353 -.1033431 .0368777 lwt | -.0120948 .0066158 -1.83 0.068 -.0250617 .000872 race | .4462621 .2150445 2.08 0.038 .0247827 .8677415 smoke | .9255414 .3980923 2.32 0.020 .1452947 1.705788 ptl | .5397383 .3469187 1.56 0.120 -.1402099 1.219686 ht | 1.799337 .6872194 2.62 0.009 .4524118 3.146262 ui | .7148045 .4634311 1.54 0.123 -.1935037 1.623113 _cons | -.1029665 1.284609 -0.08 0.936 -2.620754 2.414821 ------------------------------------------------------------------------------.. // Compute the mean prediction, Pr(low), over each level of smoking status,. // adjusting for the mean of each predictor within smoking status: . adjust, pr by(smoke) ------------------------------------------------------------------------------- Dependent variable: low Equation: low Command: logit Variables left as is: age, lwt, race, ptl, ht, ui ------------------------------------------------------------------------------- ---------------------- smoked | during | pregnancy | pr ----------+----------- 0 | .22079 1 | .395668 ---------------------- Key: pr = Probability . margins, over(smoke) at((means) *) Adjusted predictions Number of obs = 189 Model VCE : OIM Expression : Pr(low), predict() over : smoke at : 0.smoke age = 23.42609 (mean) lwt = 130.9043 (mean) race = 2.095652 (mean) smoke = 0 (mean) ptl = .1217391 (mean) ht = .0608696 (mean) ui = .1304348 (mean) 1.smoke age = 22.94595 (mean) lwt = 128.1351 (mean) race = 1.459459 (mean) smoke = 1 (mean) ptl = .3108108 (mean) ht = .0675676 (mean) ui = .1756757 (mean) ------------------------------------------------------------------------------ | Delta-method | Margin Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- smoke | 0 | .2207901 .0417458 5.29 0.000 .1389698 .3026104 1 | .3956685 .0609789 6.49 0.000 .2761519 .515185 ------------------------------------------------------------------------------.. // Compute the mean prediction, Pr(low), over each level of smoking status,. // adjusting for the overall mean of each predictor (except smoking status): . adjust age lwt race ptl ht ui, pr by(smoke) ------------------------------------------------------------------------------- Dependent variable: low Equation: low Command: logit Covariates set to mean: age = 23.238095, lwt = 129.82011, race = 1.8465608, ptl = .1957672, ht = .06349206, ui = .14814815 ------------------------------------------------------------------------------- ---------------------- smoked | during | pregnancy | pr ----------+----------- 0 | .214918 1 | .408544 ---------------------- Key: pr = Probability . margins, over(smoke) at((omeans) * (asobserved) smoke) Predictive margins Number of obs = 189 Model VCE : OIM Expression : Pr(low), predict() over : smoke at : 0.smoke age = 23.2381 (omean) lwt = 129.8201 (omean) race = 1.846561 (omean) ptl = .1957672 (omean) ht = .0634921 (omean) ui = .1481481 (omean) 1.smoke age = 23.2381 (omean) lwt = 129.8201 (omean) race = 1.846561 (omean) ptl = .1957672 (omean) ht = .0634921 (omean) ui = .1481481 (omean) ------------------------------------------------------------------------------ | Delta-method | Margin Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- smoke | 0 | .2149182 .0435287 4.94 0.000 .1296035 .3002328 1 | .4085436 .0662837 6.16 0.000 .2786299 .5384573 ------------------------------------------------------------------------------ <end> * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/

* * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/

**References**:**Re: st: -margins- vs -adjust-***From:*[email protected] (Jeff Pitblado, StataCorp LP)

- Prev by Date:
**Re: st: Kappa Weights** - Next by Date:
**Re: st: re: creating number of days per month** - Previous by thread:
**Re: st: -margins- vs -adjust-** - Next by thread:
**Re: st: -margins- vs -adjust-** - Index(es):

© Copyright 1996–2024 StataCorp LLC | Terms of use | Privacy | Contact us | What's new | Site index |