Announcement

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

  • Line graph with multiple variables and repeated measures

    Hello Stata Forum,

    I've searched this forum and other online sources for what seems like a simple question. Alas, I have not found a solution.
    I have the following continuous variables Int, Int_SN, Int_SO that were measures in the same group of people at Visit 1, 2, 3, 4, 5.
    I'd like to create a graph with means and standard deviations at each time-point for all three variables on the same graph. My data is currently in long form.
    profileplot seems to only do one variable at a time and I can't see how to overlay them.
    I've also tried with sparkline and xtline but can't seem to get it to work.
    I can make the graph in excel but it doesn't handle the standard deviations easily. I'm looking for something like this but includes standard deviations that I can run on multiple datasets in Stata.
    I've also attached the dataset.

    Thank you in advance!
    Click image for larger version

Name:	Capture.PNG
Views:	2
Size:	12.8 KB
ID:	1511649


    Attached Files

  • #2
    What is it that you're trying to show? What's the point of your graph? Overlaid cell standard deviations on a longitudinal plot of unconditional means of repeated measurements might be taken by your audience's members as a waste of their time.

    Comment


    • #3
      I'm trying to show a visual representation of change in means with standard deviations over the 5 visits. This is what my client has requested so no it is not a waste of the audience's time.

      Comment


      • #4
        If you want a graph like what you attached in #1, Stata can do it easily. And you mentioned -profileplot-, it allows several variables. So I can't follow your problems.
        Code:
        egen mean_of_int=mean(Int), by(Visit)
        egen mean_of_int_sn=mean(Int_SN), by(Visit)
        egen mean_of_int_so=mean(Int_SO), by(Visit)
        egen sd_of_int=sd(Int), by(Visit)
        egen sd_of_int_sn=sd(Int_SN), by(Visit)
        egen sd_of_int_so=sd(Int_SO), by(Visit)
        
        twoway line mean_of_int mean_of_int_sn mean_of_int_so sd_of_int sd_of_int_sn sd_of_int_so Visit, sort lpattern(solid dash dot longdash shortdash dash_dot) legend(row(2)) name(g1)
        profileplot mean_of_int mean_of_int_sn mean_of_int_so sd_of_int sd_of_int_sn sd_of_int_so, by(Visit) plot1opt(lpattern(solid)) plot2opt(lpattern(dash)) plot3opt(lpattern(longdash)) plot4opt(lpattern(shortdash)) plot5opt(lpattern(dash_dot)) legend(row(2)) name(g2)

        Comment


        • #5
          Thank you that is helpful, although that is not exactly what I was looking for. I should have been more clear about the standard deviation. That would be represented as error bars around the mean at each Visit point. The error bars could be standard deviation or standard error. I've made the graph in Excel with standard error bars. Thank you in advance for you help.
          Click image for larger version

Name:	Interconnected.JPG
Views:	1
Size:	42.2 KB
ID:	1512102
          , see below.
          Attached Files

          Comment


          • #6
            If your client is interested in a visual representation of change in means, then consider plotting the change of means ± s.e. at each successive visit.

            Anyway, take a look at the following as a starting point. It graphs the predictions (means accounting for the random effect) ± 1 s.e. You could explore adding covariances to the model if you think that that might help.

            Code:
            version 16.0
            
            clear *
            
            import excel GraphData.xlsx, sheet(Sheet1) firstrow
            
            encode Userid, generate(uid) label(UserIDs)
            drop Userid
            
            rename Int Int_nu
            rename *, lower
            rename int_* *
            
            // (You've got ceiling effects)
            set more on
            dotplot sn, over(visit) center median bar ylabel( , angle(horizontal) nogrid)
            more
            dotplot so, over(visit) center median bar ylabel( , angle(horizontal) nogrid)
            more
            dotplot nu, over(visit) center median bar ylabel( , angle(horizontal) nogrid)
            set more off
            
            // Your graph (fixed-effects means and s.e.)
            gsem (sn so nu <- M[uid] i.visit), nocnsreport nodvheader nolog
            margins visit
            marginsplot , level(68.27) title("") caption("circles - nu triangles - sn squares - so") ///
                plot1opts(lcolor(black) msymbol(circle) msize(medium) mfcolor(white)) ///
                ci1opts(lcolor(black)) ///
                plot2opts(lcolor(black) msymbol(triangle) msize(medium) mfcolor(white)) ///
                ci2opts(lcolor(black)) ///
                plot3opts(lcolor(black) msymbol(square) msize(medium) mfcolor(white)) ///
                ci3opts(lcolor(black)) ///
                ylabel( , angle(horizontal) nogrid) ///
                    legend(off)
            
            exit
            I've been admonished that, at least in statistical consultation, the realm of things that a client requests and the realm of things that are a waste of the client's time (or worse) at least occasionally overlap.

            Comment

            Working...
            X