Announcement

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

  • Margins Plot Scale Problem (on x-axis)

    Dear all,

    I am having a difficult time correcting an x-axis scale for marginsplot command.
    I want to see how x1 changes based on x2 values.

    Here is an essence of what I did:

    xtreg y on x1 x2 x1*x2, fe

    sum x2, det
    to get the statistics of x2
    at following distribution:
    5% -.77
    10% -.65
    25% -.52
    50% -.43
    75% -.31
    90% -.28
    95%. -.12

    margins, dydx(x1) at(x2=-.77) at(x2=-.65) at(x2=-.52) at(x2=-.43) at(x2=-.31) at(x2=-.28) at(x2=-.12)

    I tried different codes to fit in the scale:

    marginsplot, recast(line) recastci(rarea)

    => I would get really badly scaled axis with labels "variablename at = value"

    marginsplot, recast(line) recastci(rarea) xlab(-1(0.2)0)
    marginsplot, recast(line) recastci(rarea) xlab(-.77 "5" -.65 "10" -.59 "25" -.48 "59" -.36 "75" -.28 "90" -.24 "95")

    => When I tried to correct the label by giving a specific value, I also get a badly scaled xaxis, where all values will be on the left.
    (attachment two)

    Could someone provide some help on this scaling issue.

    Best,






    Attached Files

  • #2
    Your problem is in the specification of your multiple at() options.

    When you do that, each at() option creates its own set of margins results; in your case, each of those sets has one margin calculation. When there are multiple at() specifications like that, -marginsplot- puts each one on the x-axis, spaced out equally. The fact that your plot isn't a straight line is an indication that the x-axis scaling is off . . . in this case, the values on the x-axis are not values of x2, but rather 1, 2, 3 ... indexing the at-options.

    You don't provide your data (or the syntax you used to estimate the model), but this illustrates the issue. Note especially the even spacing on the x-axis, despite the uneven intervals of weight.

    Code:
    sysuse auto
    reg mpg c.weight##c.price
    margins, dydx(price) at(weight=2000) at(weight=2500) at(weight=10000)
    marginsplot, title(wrong)
    Click image for larger version

Name:	g1.png
Views:	1
Size:	13.8 KB
ID:	1526484


    Instead you want to specify a *list* of values for x2 in a single at() option, like this:

    Code:
    margins, dydx(price) at( weight=(2000 2500 10000) )
    marginsplot, title(Correct) xlab(2000 "2k label" 2500 "2.5k label" 10000 "10k label")
    Click image for larger version

Name:	g2.png
Views:	1
Size:	13.9 KB
ID:	1526485

    Comment


    • #3
      Thank you very much Nicholas.
      Yes, the problem was the multiple at function that I used !
      I was able to get the graph straightened out

      Comment

      Working...
      X