Announcement

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

  • scatterplot

    I would like to do several scatterplots were I plot the correlation btw mortality and covid-cases and were I would like to identify the treatment and control by different colors, this will be done for each month. I don't know if I have done the best way but by using the following code I get a nice and neat scatterplot but were I have to do it separattly in four figures, what I now want to do is to merge all of them into one big figure but with several smaller plots. Any body knows how I can do this the best way?

    twoway (scatter mortality_1000_treated new_cases_1000indiv ) (scatter mortality_1000_nontreated new_cases_1000indiv) if time== tm(2020m3)
    twoway (scatter mortality_1000_treated new_cases_1000indiv ) (scatter mortality_1000_nontreated new_cases_1000indiv) if time== tm(2020m4)
    twoway (scatter mortality_1000_treated new_cases_1000indiv ) (scatter mortality_1000_nontreated new_cases_1000indiv) if time== tm(2020m5)

    /David


  • #2
    Is this what you're looking for?
    Code:
    sysuse nlsw88
    scatter wage hours if industry == 4, mcolor(red) name(graph1)
    scatter wage hours if industry == 6, mcolor(navy) name(graph2)
    scatter wage hours if industry == 11, mcolor(green) name(graph3)
    scatter wage hours if industry == 12, mcolor(purple) name(graph4)
    graph combine graph1 graph2 graph3 graph4
    David Radwin
    Senior Researcher, California Competes
    californiacompetes.org
    Pronouns: He/Him

    Comment


    • #3
      It is exactly what I wanted, thanks for the help!

      Comment


      • #4
        A follow up question that I realised now - how do I empty the saved graphs, so that I don't need to change name for the graph every time I do a change?

        Comment


        • #5
          perhaps this
          Code:
          sysuse nlsw88
          scatter wage hours if industry == 4, mcolor(red) name(graph1, replace)
          scatter wage hours if industry == 6, mcolor(navy) name(graph2, replace)
          scatter wage hours if industry == 11, mcolor(green) name(graph3, replace)
          scatter wage hours if industry == 12, mcolor(purple) name(graph4, replace)
          graph combine graph1 graph2 graph3 graph4

          Comment


          • #6
            I'm not at my computer now, but.... couldn't this be accomplished perhaps with Nick Cox's sepscatter?

            You'd simply make a scatter plot with your variables as normal, including only the groups you're interested in, and then separate them by the industry.... and then, as Sonny says, bada boom, bada bing, one scatterplot to rule them all.

            Yeah, in fact if I were you, I'd do that, and have the Correlation Coefficients per industry in the notes section of the graph. But, perhaps I'm wrong here.

            Comment


            • #7
              An alternative to #2 and #5 is

              Code:
              . sysuse nlsw88, clear 
              (NLSW, 1988 extract)
              
              . scatter wage hours if inlist(industry, 4, 6, 11, 12), by(industry) ms(oh)
              .
              sepscatter mentioned in #6 is from SSC and was discussed in https://www.statalist.org/forums/for.../general/3803- It is for a different data structure, but could be made relevant with a reshape.


              Comment


              • #8
                It worked perfectly with both alternatives. Thanks for your help!

                Comment

                Working...
                X