Announcement

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

  • Scatter plot: connecting points to create multiple lines

    I have data for individuals showing whether they received a particular service, by quarter and by district (11 districts in total). The 'service' variable is binary (0=did not receive service, 1=received service). I want to create a scatter plot of the % of people who received the service by quarter, with the points connected by lines, and a different line for each district. I typed the following:

    egen display = mean(100*service), by(quarter district)
    separate display, by(district) veryshortlabel
    scatter display? quarter, connect(direct)

    The scatter plot is correct, but the points are only connected for the first of the 11 districts (display1). How can I get the connect(direct) option to apply to all 11 districts (display1-display11)?

    (I don't want to create a line graph as a couple of districts only have data for one quarter. They won't appear on a line graph as individual data points are not displayed and the msymbol option doesn't apply.)

    Thank you!

  • #2
    Code:
    connect(direct ..)
    That is, as you found, you over-wrote the default of not connecting only for the first y variable shown. The extra .. are syntax to do that for all variables.

    Comment


    • #3
      Amazing, thank you Nick. That produces exactly the chart I want. So simple!

      Comment


      • #4
        Sorry, one more question. I have realised that the chart only displays the first 9 of my 11 districts. Any idea how I can get the remaining two sets of connected points to appear? (There are definitely non-missing data points for display10 and display11)
        Last edited by Catherine Bunting; 21 Mar 2024, 08:16.

        Comment


        • #5
          It's hard for me to say more without seeing the data, at least for those two districts.

          Comment


          • #6
            I've worked out that it's to do with the use of questions marks in:

            scatter display? quarter, connect(direct..)

            If I include one question mark (display?) I get lines for display1 to display9. If I include two question marks (display??) I get lines for display10 and display11 only.

            So I typed the following:

            scatter display? display?? quarter, connect(direct..)

            Now everything looks fine. Phew!

            Comment


            • #7
              Indeed. I should have spotted that! Excellent catch.

              Comment

              Working...
              X