Announcement

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

  • Catplot over option

    Hi Statalist

    I am using Stata/SE 17.0. I want to make a graph using the user-written demand catplot.

    Let's say I have a variable called sample_groups that splits my sample into three groups and then I have a categorical variable that we can call category_var numbered from 1 to 5 (it is numbered numerically but each number shows a different category, e.g. 1 = like it very much, 2 = like it a bit, 3 = neutral,, etc)

    you can use this to generate some data

    clear
    set obs 120
    egen sample_groups = seq(), from(1) to(3)
    generate category_var = runiformint(1,5)



    I want to create a graph that looks something like this:
    Click image for larger version

Name:	Screenshot 2024-09-06 123618.png
Views:	1
Size:	3.4 KB
ID:	1763190




    Meaning, the count in each category over the sub-samples shown in different colours

    I tried:
    catplot category_var , over(sample)
    but that just makes three graphs (almost the same as using the by option)
    Screenshot 2024-09-06 123811.png

    Any advice would be super helpful!

  • #2
    Thanks for the clear data example.

    catplotis from SSC. (It's where commands come from that should be mentioned.)


    For what you want, you need to offer sample_groups as if it were the outcome, regardless of how you think of it.

    Although catplot supports over() by virtue of being a wrapper for (in this case) graph hbar, the syntax was intended to follow a pattern

    catplot outcome [predictors] , [options]

    Code:
    clear
    set obs 120
    egen sample_groups = seq(), from(1) to(3)
    generate category_var = runiformint(1,5)
    
    catplot sample_groups category_var,  asyvars

    Comment


    • #3
      Works like magic!! Thanks Nick - exactly what I needed

      Comment

      Working...
      X