Announcement

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

  • catplot of multiple variables

    Hello,

    I am wondering how I can catplot multiple variables. For example, I have five variables named count_truancy, count_physmal, count_physcare, count_mental, and count_health. Each of these variables =1 a certain number of times. I.e., truancy=1 1073 times, physmal=1 900 times and so on. I want a catplot type graph to show how many times each equals 1. I saw an example like the below, which is how I would love my graph to look. However, these aren't mutually exclusive so combining them into one variable messes up the counts (if I make one variable and do replace, it changes the numbers). Is there a better command for frequencies of dummy variables all on one graph? I don't really want to do graph combine because I want them to show all in one plot so it is easy for a reader to see how many more count_truancy there is than count_physmal and so on. Thanks! -CJ

    Click image for larger version

Name:	Picture1.png
Views:	2
Size:	24.4 KB
ID:	1676158

    clear
    input float(count_truancy count_physcare)
    1 0
    1 1
    0 1
    1 1
    end
    [/CODE]

    Attached Files

  • #2
    catplot is from SSC as you are asked to explain please (FAQ Advice #12).

    For a (0, 1) indicator the number of occurrences of 1 is also the sum.

    So, you can automate new variables like this:

    Code:
    gen frequency = . 
    gen which = "" 
    local i = 0 
    
    foreach x in truancy physmal physcare mental health { 
        local i = `i' + 1 
        su count_`x', meanonly 
        replace frequency = r(sum) in `i'
        replace which = "`x'" in `i'
    }
    
    graph hbar (asis) frequency, over(which, sort(1) descending)
    It sounds as if you know the frequencies any way, so you can type in the variables directly. In any case you will want better text for each bar.


    Code:
    replace which = "`: var label `x''" in `i'
    uses the variable label if defined.

    There is an equivalent catplot command but it is not I think easier or more helpful.

    Comment


    • #3
      Thanks, Nick. This does this trick.

      Comment

      Working...
      X