Announcement

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

  • -margins- for multiple at specifications, but averaged together

    Dear Statalist:

    I am hoping to calculate a set of marginal effects at multiple levels of a factor variable. The twist is that I'd like to average them together (which, of course, would only make sense if it were weighted based on the distribution of that factor variable).

    As an example, I'd say to imagine a hypothetical variable of race/ethnicity that has five categories: white, black, hispanic/latino, east asian, and south asian.

    If I wanted to find the marginal effect for individuals who are white, I could use something like:
    Code:
    margins i(1).race_ethnic
    If I wanted to see the difference between white, black, hispanic/latino, etc, I could do:
    Code:
    margins i(1 2 3 4 5).race_ethnic
    But what if I wanted to see the difference between white and all of the other categories together? The way I used to do it is to recode race_ethnic into a white/nonwhite variable, which I could then put directly in the regression equation. That would allow me to use the following:
    Code:
    margins i(0 1).white
    That's probably the cleanest way to do it in a simple, one-off comparison. But it gets really messy if you want to compare white to all other categories, and black to all other categories, and hispanic/latino to all other categories, etc. That would necessitate a bunch of regressions, when the better way to do it is just keep it as one larger factor variable. Furthermore, grouping them together creates a rather heterogeneous reference group, and putting them all together might have some strange effects on the other coefficients in the model.

    I suppose I could get what I want in a more disaggregated modeling framework, by predicting the effect of race/ethnicity for each respondent, and then collapsing the dataset while taking the mean of that effect. That sounds like a mess for a number of reasons, and a whole lot could go wrong doing it that way if you're not careful. I was hoping that there might be an option in -margins- that I missed that allows me to do that. Or maybe there are other commands, user written or otherwise, that might help.

    Thank you for your time,
    Jonathan

  • #2
    Assuming that 1 is white, then you can do something like contrast hw.race It gives you the comparison between the current level versus all subsequent levels. The first entry will thus be the comparison of white versus all else. The subsequent entries will be less meaningful.
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      Maarten: Thanks so much for that. I'm less familiar with contrast, but it looks like it is for coefficient significance testing rather than comparisons of margins. Is that right, or am I misreading the entry? The example I gave is of a single variable, but I'm using margins to look at some interaction terms. So, for example, I was hoping to look at how the effect of being white changes as income goes from, say, $20,000 to $40,000 per year in income, and then compare it to the effect of "all other" going from $20,000 to $40,000 in income. Reading through the entry, -contrast- looks like it might be able to do that using the -equations- options?

      Thanks so much,
      Jonathan

      Comment


      • #4
        No, contrasts is much more related to margins than to the raw coefficients. Terminology and use is very discipline dependent in this part of statistics, so you need to keep that in mind when reading the documentation.
        ---------------------------------
        Maarten L. Buis
        University of Konstanz
        Department of history and sociology
        box 40
        78457 Konstanz
        Germany
        http://www.maartenbuis.nl
        ---------------------------------

        Comment


        • #5
          Maarten, thank you so much for this.

          I've been looking at the documentation and playing around with it a little bit. Let's say I wanted to contrast hispanic / latino (race_ethnic=3) with black (race_ethnic=2) and east asian (race_ethnic=4). hw compares to all contrasts higher; jw compares to all contrasts before; gw to differences from the observation weighted grand mean. It looks like it's possible to do this with custom contrasts but I am having some difficulty with the syntax. In the documentation, it gives the example of

          Code:
          contrast {race -1 1 0}

          Which in the example would, if I'm not mistaken, test the effect of white versus black (1 vs 2). Then it gives the example of:

          Code:
          contrast {race -1 0 1}
          Which in the example I've given so far would test the effect of white versus hispanic / latino (1 vs 3).

          I can't seem to back into how this syntax works. My gut instinct is that the -1, 1, and 0 represent different levels, so that -1 represents the base contrast and 1 represents the group it's being contrasted with. So that would mean that

          Code:
          contrast {race 0 1 -1 1 0}
          Would compare level 3 with levels 2 and 4?

          But then, I'm also looking at it later and it appears you can weight them differently (by specifying -0.2, or 0.4). It then gives an example of comparing the first and second to the third and fourth groups. So what that mean that I would have to do is:

          Code:
          contrast {race 0 0.5 -1 0,5 0}
          Of course, I think it's possible that we could do something else with variable recoding trickery to get to the same point. If I were to recode the variable so that black=5 and south asian=2, then I could get away with the code:

          Code:
          contrast hw3.race
          Since I would have recoded everything I cared about in the contrast to after it.

          In terms of interactions, it looks like in the example using hw, I could do:

          Code:
          contrast hw3.race#inc.20000 hw3.race#inc.40000
          To get the contrasts between category 3 and 4/5 when income is set to $20,000, and between category 3 and 4/5 when income is set to $40,000.

          There are no examples of custom contrasts using continuous variable interactions, and I'm not sure it would work at all given that there are approximately an infinite number of values of for continuous variables and you have to put in a 0 for contrasts you don't care about.

          How far off am I with this so far?

          Thanks,
          Jonathan

          Comment


          • #6
            After all this, I realized that the -over- option might do what I want. I'm currently testing it out to see if it does what I expect it to; if anyone has experience with using it, I would love to hear about it.

            Comment


            • #7
              I thought I would update everyone--the way to do this is with the -over- option.

              So, if you want to compare the marginal effects for category 1 (say, black respondents) versus two others (say, south asian and east asian respondents) you can create a new variable where 1=black and 2=south asian and east asian respondents, and then you can do the -over- option to compare the two effects. We had to do some extra calculations to make sure it actually did that. You can also do this using -contrast-, if I am understanding it correctly, but it's a bit more limited.

              Comment

              Working...
              X