Announcement

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

  • Multiple lines for values of a variable on a graph

    I am working on Covid from various counties and regions in a particular US State. In order to get trend lines for several counties on a single graph I have written code like the following:
    Code:
    twoway (line cum_case_n day_ob if county == "Brown", sort) ///
        (line cum_case_n day_ob if county == "Racine", sort) ///
        (line cum_case_n day_ob if county == "Milwaukee", sort) ///
        (line cum_case_n day_ob if county == "Forest", sort) ///
        (line cum_case_n day_ob if county == "Polk", sort), ///
    I have omitted the remaining title lines etc.

    While this works it is a bit tedious and I keep thinking there has to be a simpler way to do it. A by statement produces separate subgraphs. I thought there might be an over options so that one could get multiple lines on the same plot with a single graph spec but that doesn't seem to be the case. Is there any easier way to do this?
    Richard T. Campbell
    Emeritus Professor of Biostatistics and Sociology
    University of Illinois at Chicago

  • #2
    You can encode the counties, xtset the data and use xtline.

    Code:
    webuse grunfeld, clear
    xtset company year
    xtline mvalue if inlist(company, 1, 5, 7, 8, 9), overlay scheme(s1color)
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	56.9 KB
ID:	1563595

    Comment


    • #3
      Thank very much! I was so focused on this as a twoway problem that I didn't see that xtline was a simple solution. Duh....
      Richard T. Campbell
      Emeritus Professor of Biostatistics and Sociology
      University of Illinois at Chicago

      Comment

      Working...
      X