Announcement

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

  • Plotting curvilinear relationships

    Dear Statalist users,

    I have a multilevel data set and am testing a moderated inverted U-shaped relationship using the xtmixed command. I am using Stata 14.

    I am having trouble creating a nice plot of curvilinear relationships. Specifically, I want to plot the relationship at 4 different values of the moderator (min, - 1 s.d., +1 s.d., max) to show that at some point, the curve flips to a U-shape.

    This is my code:

    Code:
    mixed leadTSat gcTSat c.cGini##c.cGini##c.gcStress Maj_owner Gender cEntExp cAgeDis cTAge2 cTeamSize Sales_yes || TeamID: || ID: , mle cov(unstr)  vsquish
    
    quietly margins, at (cGini=(-0.0936(0.025)0.646) gcStress=(-1.115385 -0.3408441 0.3408441 1.115385)) level (90)
    
    marginsplot, xsize(13) ysize(8) scale(1) noci noseparator recast(line) plotopts(lwidth(medthick) lcolor(black) cmissing(n)  connect(direct)) plot1opts( lpattern(dot)) plot2opts(lpattern(dash_dot_dot)) plot3opts(lpattern(dash) ) plot4opts(lpattern(solid)) plotregion(fcolor(white)) graphregion(fcolor(white)) xtitle("Equity inequality", size(medsmall) margin(medium)) ytitle("Predicted value of satisfaction with the team", size(medsmall)  margin(medium)) legend(order(1 "Minimum" 2 "- 1 standard deviation" 3 "+ 1 standard deviation" 4 "Maximum") size(medsmall) rows(4) position(3) title(Perceived stress levels, size(medsmall) color(black))) clegend(region(fcolor(white) lcolor(white)))
    and I am also attaching a screenshot of my current plot.


    I have read many user guidelines for the options of the margins plot command and this is the best I could make it until now. However, I do not think that the graphs look good as it might be difficult for some readers to see the difference between the dashed and the dash-dotted line if the plot was displayed smaller. I would really like to have markers at the ends of the graphs but I do not manage to do so. Whenever I select markers, I get them all over each graph, which looks really messy. I only want them at the minimum and maximum of my independent variable.

    Does anyone know how I could add different markers at the ends of the single graphs? I am thankful for any advice!

    Best regards
    Sophie
    Attached Files
    Last edited by Sophie Dibbern; 08 Jan 2018, 10:58.

  • #2
    You're more likely to get a very helpful answer if you follow the FAQ on asking questions - provide Stata code in code delimiters, readable Stata output and sample data using dataex.

    If you look in the Graphic manual, you'll find Stata gives you the choice of a large number of alternative line forms. You seem to have done this. So, why don't you just pick some other line form?

    Comment


    • #3
      Phil, thank you for your comment. I did try many different options but did not find an adequate solution for me. I will just keep on trying it myself then.

      Comment


      • #4
        Not sure that you have too much flexibility with marginsplot. See an example here of how you can save the margins output and make a custom plot using twoway. For anything more concrete, you need to present a data example.

        https://www.statalist.org/forums/for...in-marginsplot

        Comment

        Working...
        X