Announcement

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

  • Scatter plot with different x and y values for each observation

    Hi,

    I am looking to recreate a similar graph to the example below with my data:
    Click image for larger version

Name:	Screenshot 2024-02-27 203633.jpg
Views:	1
Size:	35.2 KB
ID:	1744847



    Ignore the faint gray trend lines going from the top x-axis to bottom x-axis. Each colored line with dots represents a participant. Each participant has a measured y-value and x-value for about 5-10 values. The x-values are not the same for each participant since they are measured as well. So a simple scatter will not work. I am trying to figure out a way to "feed" Stata the y and x value for each participant and then have a line connecting them similar to the example figure.
    The participants are defined with the variable
    Code:
    record_id
    . To simplify the data set a bit, I will just include the 3 measures:
    Code:
    scatter om_baseline_ph_stage_1 PCrdepletion_baseline_stage1 || scatter om_ph_stage_2 PCrdepletionstage2 || scatter om_ph_stage_3 PCrdepletionstage3
    ph_stage is the y-axis and PCrdepletionstage is the corresponding x-axis. I tried adding
    Code:
    || line om_baseline_ph_stage_1 om_ph_stage_2 om_ph_stage_3 if record_id  == "first patient"
    to the end of the code, but this is clearly wrong since Stata interprets
    Code:
    om_ph_stage_3
    as the x-axis. Ultimately, I can imagine this needs some sort of loop with -levels-. Thanks very much in advance.
Working...
X