Announcement

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

  • Multiple Line Graph of Mean

    Hello!

    I'm very new to Stata (I just started using it yesterday) and I'm trying to figure out how to do a multiple line graph of the Mean of a variable.

    I want the y-axis to be DRS (shown on a scale of 0 to 14) and the x-axis to be data_point (which is 4 time points)

    and to plot the mean DRS score using 6 lines from the LTCH and Sex_AA2 variables:

    Location 1 Male
    Location 1 Female
    Location 2 Male
    Location 2 Female
    Location 3 Male
    Location 3 Female



    I created some fake cases to show you my data:


    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(ID data_point gender LTCH DRS)
    1 1 0 1  3
    1 2 0 1  2
    1 3 0 1  1
    1 4 0 1  3
    2 1 1 2  3
    2 2 1 2  4
    2 3 1 2  3
    2 4 1 2  2
    3 1 1 3  3
    3 2 1 3  7
    3 3 1 3 12
    3 4 1 3 11
    4 1 0 1  5
    4 2 0 1  4
    4 3 0 1  2
    4 4 0 1  3
    5 1 1 3  5
    5 2 1 3  4
    5 3 1 3  2
    5 4 1 3  1
    end
    label values data_point DataPoint
    label def DataPoint 1 "Pre-Move", modify
    label def DataPoint 2 "Move", modify
    label def DataPoint 3 "3 Month", modify
    label def DataPoint 4 "6 Month", modify
    label values gender Gender
    label def Gender 0 "Male", modify
    label def Gender 1 "Female", modify
    label values LTCH LTCH
    label def LTCH 1 "Location 1", modify
    label def LTCH 2 "Location 2", modify
    label def LTCH 3 "Location 3", modify

    Any help is greatly appreciated.

  • #2
    Code:
    xtset ID data_point
    xtline DRS, overlay scheme(s1color)
    or excluding the legend

    Code:
    bys ID (data_point): gen lastob=_n==_N
    xtline DRS, overlay scheme(s1color) leg(off) addplot(scatter DRS data_point if lastob , mlab(ID) mcolor(none)) xlab(1(1)4.3)
    You cannot really separate IDs 1 and 4 with method #2.

    Comment

    Working...
    X