Announcement

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

  • scatter plot by a variable and color based on a different variable

    Hi Stata users,

    I have dataset of observations from different countries as shown below


    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input byte(ded cec) str1 country str7 region
    1 0 "A" "Group 1"
    0 1 "B" "Group 2"
    1 0 "B" "Group 2"
    1 0 "A" "Group 1"
    0 1 "D" "Group 2"
    0 0 "B" "Group 2"
    0 0 "A" "Group 1"
    0 1 "D" "Group 2"
    1 0 "B" "Group 2"
    0 1 "C" "Group 1"
    0 0 "A" "Group 1"
    1 1 "D" "Group 2"
    0 0 "D" "Group 2"
    0 1 "A" "Group 1"
    1 1 "B" "Group 2"
    0 0 "D" "Group 2"
    0 1 "A" "Group 1"
    1 0 "C" "Group 1"
    1 1 "D" "Group 2"
    1 0 "A" "Group 1"
    1 1 "B" "Group 2"
    1 0 "D" "Group 2"
    1 1 "A" "Group 1"
    1 1 "D" "Group 2"
    0 0 "B" "Group 2"
    0 0 "D" "Group 2"
    0 1 "C" "Group 1"
    0 1 "B" "Group 2"
    0 1 "D" "Group 2"
    0 1 "C" "Group 1"
    0 0 "B" "Group 2"
    1 0 "D" "Group 2"
    0 0 "C" "Group 1"
    1 1 "B" "Group 2"
    0 1 "C" "Group 1"
    1 1 "D" "Group 2"
    0 0 "B" "Group 2"
    1 0 "C" "Group 1"
    0 1 "C" "Group 1"
    1 1 "B" "Group 2"
    1 0 "D" "Group 2"
    1 0 "D" "Group 2"
    0 0 "C" "Group 1"
    0 0 "C" "Group 1"
    1 1 "D" "Group 2"
    0 1 "C" "Group 1"
    1 0 "C" "Group 1"
    0 0 "D" "Group 2"
    1 1 "C" "Group 1"
    0 1 "D" "Group 2"
    end
    I would like to have a scatter plot ded and cec by country with colour coding based on region. Any help would be greatly appreciated.

    Thanks in advance!

  • #2
    Code:
    ssc desc sepscatter

    Comment


    • #3
      I agree with Andrew Musau that sepscatter is a good fit to your question. but the evidence of your data example is that your variables are (0. 1) in which case a scatter plot is a recipe for over-plotting and jitter() doesn't really help.

      Code:
      . sepscatter ded cec, by(country) separate(region)
      
      . sepscatter ded cec, by(country) separate(region) jitter(3)
      What is the relationship of country and region? Which is set and which is subset? Why obfuscate your data?
      .

      Comment


      • #4
        Nick Cox Thanks so much for your advice. It's super helpful.

        To answer your question - country is subset of region. Sorry for how the data structure. The data was collected for respondents from countries all over the word. The goal is to determine whether there are any regional differences based on analysis done at country level.

        Comment

        Working...
        X