Announcement

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

  • Line graph for multiple time points

    Hi first time posting here, would appreciate any help as I am quite stuck on this. Have tried accessing help and the forum for answer to no avail.
    Variable: GFR1 GFR2 GFR3 GFR4 - indicating GFR at 4 different time points
    Each variable is complete for 50 participants - that has been divided in to two groups (patient vs. control) categorically as 1 and 2 under another variable: TYPE
    I am trying to plot a single graph with Y-axis as the median GFR value and X-axis as the different time points 1-4 and being seperated by TYPE
    Thank you in advance.

  • #2
    That is tricky with your data structure, but not impossible.

    By far the simplest of the tricky ways is to reshape first.
    Your data structure is poorly chosen for almost all Stata purposes.

    Here are some silly data, absent a data example from you (please do read the FAQ Advice).

    Code:
    clear
    set obs 4
    gen type = cond(_n <= 2, 1, 2)
    input GFR1 GFR2 GFR3 GFR4
    1 2 3 4
    5 6 7 8
    9 10 11 12
    13 14 15 16
    dataex
    
    * you start here: if you have an identifier, use it instead of id
    gen id = _n
    reshape long GFR, i(id) j(time)
    list
    
    egen median = median(GFR), by(type time)
    label var median "median GFR (some units go here)"
    twoway connected median time if type == 1, lc(orange) mc(orange) ms(Oh) ///
    || connected median time if type == 2, lc(blue) mc(blue) ms(+) ///
    legend(order(1 "type 1" 2 "type 2"))
    Click image for larger version

Name:	GFR.png
Views:	1
Size:	20.6 KB
ID:	1508981

    Last edited by Nick Cox; 23 Jul 2019, 00:40.

    Comment


    • #3
      Nick Cox thank you kindly for helping me out.
      I do have a long form for the dataset as well. I have been successful in creating a median variable, but it is coming back as median is not a two way plot?

      Comment


      • #4
        Please do read the FAQ Advice and show us your exact code within CODE delimiters.

        Possibly you left out connected or line where it belongs.
        Last edited by Nick Cox; 23 Jul 2019, 01:47.

        Comment


        • #5
          dear Nick Cox thank you very much for your cadvice, expertise and time. I manage to plot the graph!!

          Comment

          Working...
          X