Announcement

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

  • Problems changing the look of a line connecting predicted values in a twoway scatter, using connect and lpattern

    Hello,

    Im trying to produce a twoway scatter using Stata SEv13 and the following code:

    regress ssscore ageatdeath if sex==1
    predict male
    regress ssscore ageatdeath if sex==2
    predict female
    twoway (scatter male ageatdeath, connect(l) msymbol(i) lpattern(dash)) (scatter female ageatdeath, connect(l) msymbol(i)), title("social support by age and sex") ///
    ytitle(predicted social support score) xtitle(age at last wave) ///
    legend(order(1 "male" 2 "female"))

    Here's the graph i produce:

    Click image for larger version

Name:	scatter.png
Views:	1
Size:	23.8 KB
ID:	1450057

    The problem is that the lpattern(dash) option only seems to change the line in the legend and not the look of the line in the graph.

    Please can someone advise me where im going wrong? Ive tried changing the colour and thickness and both of these options work well.

    p.s. I specifically want to plot the predicted values of ssscore (rather than using lfit) because later i want to mi impute the missing ssscore data and use mi predict to get the predicted values (i dont think i can use lfit with imputed datasets - but please correct me if im wrong).

    Many thanks,
    Joanna

  • #2
    I think you are missing a sort option. If you look closely at one line there's a hint that it is trying to draw a dashed line but the connection is in the order of the observations, not from left to right across the graph. With some simplifications:


    Code:
    line male female ageatdeath, lpattern(dash solid) title("social support by age and sex") ///
    ytitle(predicted social support score) xtitle(age at last wave) legend(order(1 "male" 2 "female")) sort
    I would move the legend too:

    Code:
    line male female ageatdeath, lpattern(dash solid) title("social support by age and sex") ///
    ytitle(predicted social support score) xtitle(age at last wave) legend(order(2 "female" 1 "male") col(1) ring(0) pos(1)) sort

    Comment


    • #3
      Brilliant! Thanks Nick. This works beautifully and simplification and repositioning of the legend is much better.
      j

      Comment

      Working...
      X