Announcement

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

  • Problem using combomarginsplot command for multiple margins from single regression

    Hello,

    I am using Stata Version 14.2. I am trying to use the combomarginsplot command to create a single marginsplot of multiple margins from a single regression (using xtreg).

    Here is an example of the code I am using:
    xtreg depvar c.(interactionvar1 intreactionvar2 interactionvar3)##c.indepvar1 controlvar1 controlvar2///
    margins, dydx(indepvar1) at(interactionvar1=(-2 -1 0 1 2)) saving(m_1, replace)///
    margins, dydx(indepvar1) at(interactionvar2=(-2 -1 0 1 2)) saving(m_2, replace)///
    margins, dydx(indepvar1) at(interactionvar3=(-2 -1 0 1 2)) saving(m_3, replace)///
    combomarginsplot m_1 m_2 m_3, labels ("Margins 1" "Margins 2" "Margins 3")///

    At the end of this, I receive the following results and error code:

    Warning: statistics differ for interactionvar1: file 1=values, file 3=asobserved; using first (values)
    Warning: statistics differ for interactionvar3: file 1=asobserved, file 3=values; using values
    Warning: statistics differ for interactionvar2: file 2=values, file 3=asobserved; using first (values)
    Warning: statistics differ for interactionvar3: file 2=asobserved, file 3=values; using values
    Warning: statistics differ for interactionvar1: file 1=values, file 2=asobserved; using first (values)
    Warning: statistics differ for interactionvar2: file 1=asobserved, file 2=values; using values
    local: _at3 master: _at1
    file 2 _u_at_vars don't match file 1
    r(198);

    I am not sure what exactly this means nor what I am doing wrong here.

    I am guessing that maybe the issue is with using the dydx command for the margins of interactions? I use this because I am interested in the average marginal effect of my independent variable of interest when interacted with my three different interaction variables (i.e., interactionvar1, interactionvar2, interactionvar3). If this is the issue, I wonder if the preferred alternative approach for this would be combining three separate marginsplots graphs into a single graph or using an alternative margins command to dydx.

    I apologize if this did not make sense. Any advice anyone might have for me would be VERY appreciated.

    Thank you!!!
    Last edited by Catie Bailard; 11 Jul 2018, 14:29.

  • #2
    Upon more reflection, I think the issue is more likely that I have three different variables mapped onto the x-axis across the three different saved margins results. Even though the scale for the x-axis has the same range for all three variables (i.e., -2, -1, 0, 1, 2), Stata may not know what to do with this. I tried tricking it to think it is the same variable being mapped along the x-axis for all three margins results using the replace command to rename each of the three variables with the same generic name, and then rerunning the primary regression three times with each variables subbed out with the generic name, but this did not seem to do the trick.

    I wonder, if this is the problem, if anyone has any other ideas as far as a work around?

    Thank you!!!

    Comment


    • #3
      You are correct that combomarginsplot does not allow you to combine multiple different variables onto a single X-axis.

      This is on purpose, as in my view this is likely to be very unclear to your reader/viewer. We see many graphs with multiple y-axis variables; we rarely see graphs with multiple X-axis variables, so this is likely to cause confusion. I would strongly recommend separate plots for each IV, using, e.g., graph combine.

      But, if you really want to fool combomarginsplot, you can. Here's a silly example that uses regress (instead of xtreg) but the approach works either way:

      Code:
      sysuse auto
      
      // desired regression:  reg mpg gear headroom 
      gen XXX = gear
      reg mpg XXX headroom
      margins, at(XXX=(1(1)5)) saving(m1, replace)
      
      drop XXX
      gen XXX=headroom
      reg mpg XXX gear
      margins, at(XXX=(1(1)5)) saving(m2, replace)
      
      combomarginsplot m1 m2, xtitle("Confusing X axis") label("Gear ratio" "Headroom") name(g1, replace)
      
      
      // unsolicited advice: do this instead
      reg mpg gear headroom
      margins, at(gear=(1(1)5))
      marginsplot, name(mp1, replace)
      
      margins, at(head=(1(1)5))
      marginsplot, name(mp2, replace)
      
      graph combine mp1 mp2, ycommon name(g2, replace)

      Comment


      • #4
        Great!

        Thank you so much for your time and help on this! It is super helpful. I will experiment with both approaches for the sake of familiarizing myself with different potential "fixes", but agree the second is preferable.

        Thank you again!

        Comment

        Working...
        X