Announcement

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

  • Help with marginsplot - removing a vertical line (Not yline(0)!)

    Hello,

    So basically I'm having trouble with the output I get when I'm running a marginsplot (I've attached the regression-output and the marginsplot).

    The command is:

    reg Holdningsindeks i.Treatment##c.Tryghedsindeks, robust
    margins, dydx(*) at(Tryghedsindeks=(0(0.1)5))
    marginsplot, yline(0, lpattern(dash) lcolor(black)) graphregion(color(white)) xlabel(#5) recast(line) recastci(rline) ciopts(lpattern(dash)) ytitle("Marginal effekt af afsender") title("Effekt af politisk afsender på holdning givet tryghed") xtitle(Tryghed) noci name(T_uden_konf11)


    ** (The yline(0) is supposed to be there - it's not the problem I'm trying to solve ;-) ). **

    The problem is the vertical green line (y=0,28) and how to remove it.

    The X-variable is 1=Control group, 2=Treatment 1 and 3=Treatment 2.
    The Y-variable is a "position/attitude towards the treatment" from 1-5.
    The Z-variable is the interaction/moderation variable.

    Click image for larger version

Name:	Regressionsoutput.png
Views:	1
Size:	54.5 KB
ID:	1444707


    Click image for larger version

Name:	Maginsplot.png
Views:	1
Size:	70.8 KB
ID:	1444708



    I'm looking forward to hearing from you


    Kind regards
    Mathias

  • #2
    Hi Mathias,

    I'm not sure you want to remove the horizontal green line, given that it is your reference line. But assuming you still want to, there is always the crude way of creating the graph, then editing the graph interactively, and 'hiding' the green line.

    The coding way to achieve this is...
    Code:
    webuse nhanes2 , clear
    regress height c.weight##i.race
    margins , dydx(*) at(weight=(40(5)100))
    marginsplot , plot1opts(lcol(none) msym(none)) ci1opts(lcol(none))
    You can adapt this code for your own context. Let me know if you have any questions.
    Last edited by Matt Warkentin; 18 May 2018, 13:48.

    Comment


    • #3
      Hi Matt,

      Thank you for your quick answer - the reason I want to hide the vertical line/lines (with a control variable, I just added) is more of an aestetic question for my paper/assignment!

      Just one last thing, how do you remove the irrelevant/variables I just "hid" with the command in the "box" beneath the figure. I'm talking about "Tryghedsindeks" and "Koen/Køn".

      The command is so far:
      marginsplot, plot3opts(lcol(none) msym(none)) ci3opts(lcol(none)) plot4opts(lcol(none) msym(none)) ci4opts(lcol(none)) yline(0, lpattern(dash) lcolor(black)) graphregion(color(white)) xlabel(#5) recast(line) recastci(rline) ciopts(lpattern(dash)) ytitle("Marginal effekt af afsender") title("Effekt af politisk afsender på holdning givet tryghed") xtitle(Tryghed) name(T4)




      Click image for larger version

Name:	Model 4 - god.png
Views:	1
Size:	86.8 KB
ID:	1444853


      Last edited by Mathias Jensen; 19 May 2018, 01:19.

      Comment


      • #4
        Hi Mathias,

        Just to clarify, you haven't really hidden the variable Tryghedsindeks entirely. Only the effect of that variable in those who are in the treatment group==1. The red and blue lines are the effect of Tryg in level 2 and 3 of treatment. Since the effect for only those individuals in treatment group 1 is simply the main effect of Tryg, that is what is being hidden. For the second variable you have added, Koen, it does not have an interaction term with Tryg in the model, so this is the main effect that applies equally to all and is shown in the marginsplot as just a horizontal line at the value of the regression estimated beta coefficient. You may have known this already, but I just wanted to make certain we were on the same page.

        Again following off of our example in my last reply, you can customize your legend use the following code:
        Code:
        webuse nhanes2 , clear
        regress height c.weight##i.race
        margins , dydx(*) at(weight=(40(5)100))
        marginsplot , plot1opts(lcol(none) msym(none)) ci1opts(lcol(none)) legend(order(5 "Black" 6 "Other"))
        You just need to identify the value of the label you want to include and then the label itself. Leave out any labels you do not wish to see.

        Comment


        • #5
          Maybe consider looking at the predictive margins of your factor of interest. You can then contrast them to get their marginal effects.

          Here is one way to do this using the example from Matt.

          Code:
          webuse nhanes2 , clear
          regress height c.weight##i.race
          margins race, at(weight=(40(5)100))
          marginsplot, name(pm)
          margins r.race, at(weight=(40(5)100))
          marginsplot, name(mfx)
          The predictive margins are plotted in the graph named pm.

          Click image for larger version

Name:	pm.png
Views:	1
Size:	35.0 KB
ID:	1445335


          The contrasted predictive margins are plotted in the graph named mfx.

          Click image for larger version

Name:	mfx.png
Views:	1
Size:	32.7 KB
ID:	1445336

          Comment

          Working...
          X