Announcement

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

  • Please help with overlaying xtline.

    Dear Stata Experts, I am a not-Stata-savvy researcher. My simple goal is to produce a time-graph overlaid with two curves, one curve for each day. I have transformed my data to the long format. The entire dataset and the problem can be summarised with this small dataset with just the medians of the population:

    Medianvalue Id Time
    1.00 1 1000
    0.97 1 1002
    0.90 1 1004
    0.95 1 1006
    1.00 1 10000
    0.93 1 10001
    0.91 1 10002
    0.88 1 10004
    0.92 1 10006


    The 1000-numbers are from one day and the 10000-numbers are from a second day, and each rightmost digit corresponds to same hour of the day. I did something to my patients on the second day (the "10000-day") so that already at 1 and 2 hours (10001; 10002) there was quick decrease in malignant cells (disappearing faster). I would like to produce a simple graph where the 10000 and 1000 are the respective origin at the x axis. Please note that there's an extra measurement day 2 (10001), but I hope that wouldn't be a problem.

    I simply don't understand to overlay these two curves in one graph (see attachment)

    Thank you in advance

    BE Wahlin, MD PhD

    Attached Files

  • #2
    Your existing Time variable can be used for a graph but any result will just be dominated by a gap between 1006 and 10000 that is just a side-effect of idiosyncratic coding. This may be closer to what you want.


    Code:
    clear
    input Medianvalue Id Time
    1.00 1 1000
    0.97 1 1002
    0.90 1 1004
    0.95 1 1006
    1.00 1 10000
    0.93 1 10001
    0.91 1 10002
    0.88 1 10004
    0.92 1 10006
    end
    
    gen Day = cond(Time < 10000, 1, 2)
    gen Hour = mod(Time, 1000)
    
    line Medianvalue Hour if Day == 1 || line Medianvalue Hour if Day == 2, legend(order(1 "Day 1" 2 "Day 2"))
    I can't see that xtline is especially needed or helpful here.

    Comment


    • #3
      Thank you for your kind response! Yes, that is close to what I want, and now we have the same timepoints at the two days. But when I try that on my dataset the line appears to connect to too many places (see attachment please). The real dataset is larger, of course. Is this a problem because the calculated median values are at multiple places in the data? I attach a pictute of the dataset to show you the "real" medianvalue, medrclb.

      I used xtline to produce the original graph.

      Kind regards and thank you again
      Attached Files

      Comment


      • #4
        Dear Nick, having trawled through the net, I found this solution from a certain N Cox

        https://stackoverflow.com/questions/...ultiple-groups

        with sort connect(L)

        everything works! Thank you

        Comment


        • #5
          Good that you found a solution but what solution you found is difficult to guess.

          For future questions please note our firm discouragement of screenshots with reasons why and positive suggestions on what to do instead. https://www.statalist.org/forums/help#stata

          FWIW, I can just read your screenshot if I blow it up but I see no examples there of a time variable like that in #1.

          Comment

          Working...
          X