Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Are the two margins commands equivalent?

    use https://www.stata-press.com/data/r17/margex
    logistic outcome i.sex i.group sex#group age
    margins, over(sex) at(group=(1 2 3)) post
    margins group#sex, post

    The two margins show different results. Could anyone help me and give me an explanation?

  • #2
    They are not equivalent commands. The following commands would be equivalent:
    Code:
    margins, at(group = (1 2 3) sex = (1 2)) // ASSUMING SEX IS CODED AS 1 AND 2
    margins group#sex
    The discrepancy in your own results is due to the use of -over()-. When you calculate margins -over(sex)- the results are not adjusted for age (nor any other variable in the model). When you use -at()- you get margins that adjust for all variables in the model (unless you constrain the other variables with -at()- specifications of their own). The margins you get using -over(sex)- are results that are conditional on the value of sex (i.e. they are computed only using the observations for that one sex) and therefore can never be adjusted for anything that differs across the sexes.

    There are situations where these conditional margins are the answers to the proposed research questions, but those situations are, in my experience, uncommon. When you find yourself tempted to use -over()-, think twice and make sure you really want results with no adjustment for other variables. That will only seldom be the case. So use -at()-, or put the variable in the -margins- varlist, unless you are sure about that.

    Added: I will note that if the regression model contains no other variables, then -at()- and -over()- do produce the same results.

    Comment


    • #3
      Thank you so much!

      Comment

      Working...
      X