Announcement

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

  • How to juxtapose dot graphs for two groups of a single categorical variable? (Example in post)

    Hello everyone!

    I made a dot graph using the command "graph dot", to show the division of household tasks by gender in a dataset I have collected. Currently I get two graphs side-by-side, but I would like to juxtapose the "dots" so that they're on the same axes instead.

    I used the following command:

    graph dot sharing, by(female) over(task) ytitle(Sharing of tasks)
    where "sharing" is my outcome variable (it indicates who does more of the task in the couple, from 0 doing nothing to 5 doing all of it), "female" is a binary dummy to indicate gender, and "task" is a categorical variable to indicate the type of household task.

    I get the following graph:

    Click image for larger version

Name:	Graph.png
Views:	1
Size:	61.1 KB
ID:	1619795

    Is there any way to "combine" the Men and Women graphs, so that I can see the dots for men and women on the same axis, for each task? It would make it much easier to compare e.g. if men and women both think they do most of a particular task!

    Thanks in advance for any help or pointers!

    Best wishes,
    Lucie

  • #2
    You want to switch to twoway dot. Here is an example:

    Code:
    sysuse nlsw88, clear
    *SIMILAR TO YOUR GRAPH
    set scheme s1color
    graph dot wage, over(occ, sort(1)) by(never_married)
    
    *WANTED
    preserve
    collapse wage, by(occ never_married)
    twoway (dot wage occ if !never_married, msym(oh) ///
    horiz ylab(1/13, val angle(horiz)) ytitle("")) ///
    (dot wage occ if never_married, msym(t) horiz ///
    leg(order(1 "Currently or previously Married" 2 "Never Married" ) row(2)))
    restore
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	84.4 KB
ID:	1619835

    Comment


    • #3
      Originally posted by Andrew Musau View Post
      x
      Hi Andrew, thank you so much for showing me this code - looks like exactly what I need!! I'll adapt it to my data and see how it works.

      Much appreciated!!

      Best wishes,
      Lucie

      Comment


      • #4
        Originally posted by Andrew Musau View Post
        x
        Hi Andrew,

        Thanks again very much for the code earlier, thanks to it I have now managed to create the correct graph!

        I have one last question: I am having trouble ordering the lines ("bars?"). I would like to order them from biggest to smallest value for men (or for women, either one works). The help file for dot graphs only provides solutions for the simpler syntax using "graph x over y" type overall command, whereas in our solution we are using the twoway command. This means I'm seemingly not allowed to use the usual solutions (such as the order(1, descending) type of syntax).

        Do you have any idea how I might be able to choose the order of the bars? Thanks in advance (and no worries if not!)

        Best wishes,
        Lucie

        Comment


        • #5
          Install myaxis from SSC, authored by Nick Cox.

          Code:
          ssc install myaxis, replace
          You can sort using one category (either men or women). The alignment will depend on how close these values are.

          Code:
          sysuse nlsw88, clear
          preserve
          collapse wage, by(occ never_married)
          myaxis order=occupation, sort(mean wage) subset(!never_married) descending
          set scheme s1color
          twoway (dot wage order if !never_married, msym(oh) ///
          horiz ylab(1/13, val angle(horiz)) ytitle("")) ///
          (dot wage order if never_married, msym(t) horiz ///
          leg(order(1 "Currently or Previously Married" 2 "Never Married" ) row(2)))
          restore
          Click image for larger version

Name:	Graph.png
Views:	1
Size:	84.9 KB
ID:	1619865

          Comment


          • #6
            Originally posted by Andrew Musau View Post
            x
            Hi Andrew, this is exactly what I was looking for, thank you so much! I adapted it for my dataset and it worked perfectly :-)

            Best wishes,
            Lucie

            Comment


            • #7
              If interested to learn more about myaxis see https://www.statalist.org/forums/for...e-or-graph-use

              A paper is in press for Stata Journal 21(3) 2021.

              Comment

              Working...
              X