Announcement

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

  • boxplot using categories from two variables

    Hi,
    I’m trying to put categories of two variables on a box plot, but not sure how to do it.
    I have a y variable and I want to show its mean, 25th and 75th percentile by four categories. First three categories are in variable group123 and the combination of both group 2 and 3 is in variable group4. That is the reason its not possible to make a 4-category variable because the fourth category (variable group4) are the respondents that are in either category 2 and 3 of the group123 variable.
    I get two box plots by commands below but is it possible to put them both in one graph? Have the group4 as fourth boxplot in the first graph?
    Code:
     graph box y, over(group123)
    graph box y, over(group4)
    Please, tell
    Click image for larger version

Name:	1.jpg
Views:	1
Size:	34.3 KB
ID:	1643968

    Click image for larger version

Name:	2.jpg
Views:	1
Size:	30.3 KB
ID:	1643969

  • #2
    A standard box plot shows medians not means. If you want to show means on a box plot too, you need something else. If you have picked up an understanding that box plots show means, the documentation and references for graph box are possible resources. If means was a typo on your part. so much the better.

    Otherwise what I think is precisely your problem is discussed within https://www.stata-journal.com/articl...article=gr0058

    There is a clumsier approach using graph combine but I think you'll prefer the result given by the method in the paper.
    Last edited by Nick Cox; 07 Jan 2022, 06:02.

    Comment


    • #3
      Many thanks. This is a very neat solution. Sorry for confusing about mean; yes, it was a typo.

      Comment

      Working...
      X