Announcement

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

  • Plotting two fitted lines on same scatter plot

    Hi,

    I am trying to fit two fitted lines on the same scatter plot after running an ANCOVA and two lincom commands after the ANCOVA. I would like to fit the two fitted lines from the lincom commands on the same scatter plot. I have two treatment groups, phone vs. newsletter, represented by the variable assignment_r.

    Below is a small sample of the data and the main variables:
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input long pid float(sppb_ch_12mo PCS_ch_12mo) long assignment_r
    10002  1  6.880001 1
    10005  3  8.209999 0
    10008 -1         0 1
    10011 -2     -5.68 1
    10012  0 -6.330002 1
    10013 -2  7.989998 0
    10015 -2 -3.009998 1
    10017  2     11.07 1
    10024 -1  8.670002 1
    10025  1  4.830002 0
    end
    label values assignment_r assignment_r
    label def assignment_r 0 "Newsletter", modify
    label def assignment_r 1 "Phone", modify
    Here is what I do in terms of the ANCOVA and lincom commands:
    Code:
    regress PCS_ch_12mo sppb_ch_12mo i.assignment_r 
    lincom _cons+1*sppb_ch_12mo
    lincom _cons+1*sppb_ch_12mo+1.assignment_r
    Then, I would like to put the two fitted regression lines from the two lincom commands (the first lincom command represents the newsletter group line and the second lincom command represents the phone group line) onto the same scatter plot with sppb_ch_12mo on the x-axis and PCS_ch_12mo on the y-axis. Would really appreciate any help with this.

    Thank you.



  • #2
    regplot from the Stata Journal can help.


    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input long pid float(sppb_ch_12mo PCS_ch_12mo) long assignment_r
    10002  1  6.880001 1
    10005  3  8.209999 0
    10008 -1         0 1
    10011 -2     -5.68 1
    10012  0 -6.330002 1
    10013 -2  7.989998 0
    10015 -2 -3.009998 1
    10017  2     11.07 1
    10024 -1  8.670002 1
    10025  1  4.830002 0
    end
    label values assignment_r assignment_r
    label def assignment_r 0 "Newsletter", modify
    label def assignment_r 1 "Phone", modify
    
    regress PCS_ch_12mo sppb_ch_12mo i.assignment_r 
    
    regplot, sep(assignment_r) legend(order(1 2)) scheme(s1color) fitopts(lcolor(orange blue)) ms(Oh +) mc(orange blue)

    Detail: The surrounding package includes a command rdplot which predates, and is not at all the same as, rdplot in another package So, don't overwrite that command if you are already using it.

    Comment

    Working...
    X