Announcement

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

  • Simple addplot syntax - how do I graph 2 sets of observations on one graph?

    Hi,

    Sorry to be that guy, but I can't find any stata help files or forum posts to clear this up. If anyone can recommend a change to my code that would be great.

    I've overlaid two lowess scatter plots onto one graph using the code below quite easily:

    Code:
     lowess d_Originality_Lv Complex_Problem_Solving_Lv , addplot(lowess d2_Originality Complex_Problem_Solving_Lv)
    However, when the graph is generated it shows only the observations for the first variable, 'd_Originality_Lv', against the independent var 'Complex_Problem_Solving_Lv'. The lowess lines show the relationship I want to convey, but if I could have observation dots for both the sets of data overlaid in slightly different colours, this would give some substance to the different forms of the lowess lines.

    I can't find any way to code the legend or graph code to show both sets of observations. Also, the output is okay right now and I wouldn't want to specify a legend(...) command and lose the other legend elements which appear automatically because I don't quite know how to code them myself. I could potentially work it out if need be, though.

    Thanks in advance.
    Last edited by Matthew Chapman; 29 Apr 2019, 14:36.

  • #2
    In future, please make an effort to present a data example using the dataex command. Switch to twoway

    Code:
    tw (lowess d_Originality_Lv Complex_Problem_Solving_Lv, lcolor(red)) ///
    (scatter d_Originality_Lv Complex_Problem_Solving_Lv, mcolor(red)) ///
    (lowess d2_Originality Complex_Problem_Solving_Lv, lcolor(blue)) ///
    (scatter d2_Originality Complex_Problem_Solving_Lv, mcolor(blue) ///
    scheme(s1color) legend(order(1 "My var 1" 2 "My var 2")))
    ADDED IN EDIT: In Stata 15+, you can set opacity to less than 100% to view overlapping markers. In place of mcolor(red), replace with mcolor(red%40) and mcolor(blue%40), or any number less than 100 that achieves the purpose.
    Last edited by Andrew Musau; 29 Apr 2019, 14:54.

    Comment


    • #3
      That is so helpful, Andrew, thank you! I'll use dataex in the future, didn't know about it so thank you for telling me.

      Comment


      • #4
        The lowess method has a long history (40 years from first formal publication).

        I would make here an objective and a subjective comment:

        lowess in other implementations has morphed through loess and locfit and perhaps other names too. lowess in Stata has the flavour but not necessarily exact reproducibility as compared with beasts under similar names.

        I've switched myself in Stata to using lpoly. It has more flexibility and is easier to explain through literature references.

        Comment

        Working...
        X