Announcement

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

  • help with overlapping sctater plots

    Dear All,
    I am using the code below to create multiple oberlapping scatter plots including fitted line. i am creating scatter plots for men and women for different depnedent variables and the same independent varible. when the the plot is created i don't know which color is for men and which oone is for women. what should i add the to the code to leable the colors by gender.

    thanks in advance
    Code:
    ocal j = 1
    local names
    foreach v of varlist bmi_w waistcm_w hipcm_w whratio_w fatmass_w  fmi_w fat_w bai_w vat_w ffm_w bodyweighkg_w {
         twoway (scatter `v' psaaa_w if sex==0)(scatter `v' psaaa_w if sex==1) (lfit `v' psaaa_w if sex==0)(lfit `v' psaaa_w if sex==1), name(graph`j')
         local names `names' graph`j'
         local ++j
    }
    
    graph combine `names'
    stata 15.1 mac
    Attached Files

  • #2
    Code:
    (scatter `v' psaaa_w if sex==0, mcolor(red))(scatter `v' psaaa_w if sex==1, mcolor(blue))
    Since you are using the default scheme, the order of the legend combined with the order specified in the code suggests that blue is sex==0 and red is sex==1. But the question is what does sex==1 represent? Better coding practice suggests that you should rename the variable "male" or "female" depending on the sex of the positive category.
    Last edited by Andrew Musau; 21 Feb 2020, 08:25.

    Comment


    • #3
      Thanks Andrew. sex==0 means male and sex==1 is female.

      Comment

      Working...
      X