Announcement

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

  • Plot graph of multiple categorical variables (with sub-categories) across outcome variable

    Dear all,

    If one has more than two categorical variables with two sub groups in each. I want to graph them over one binary outcome variable. To do so I tried using catplot from SSC. However, the use of the command over(yvar) . How can I do to this separately for each categorical variable. Ideally, I would like to have a single graph, where both categorical variables and their sub-categories appear as horizontal bars.

    Is there a possibility of drawing these descriptive graphs without the use of graph combine?

    Thanks.
    Last edited by Sicily Kanyu; 02 Aug 2019, 06:13.

  • #2
    You can restructure your data such that you have a group variable. Here is an example

    Code:
    sysuse auto, clear
    set seed 2019
    qui sum price, d
    gen hiprice=price>r(p50)
    qui sum mpg, d
    gen himileage=mpg>r(p50)
    rename (hiprice himileage) (cat#), addnumber(1)
    reshape long cat, i(make) j(which)
    label def which 1 "Price" 2 "Mileage"
    label values which which
    label def cat 1 "High" 0 "Low"
    label values cat cat
    catplot cat, over(foreign) over(which) scheme(s1mono)
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	18.3 KB
ID:	1510794


    In case some groups have more categories, add the -nofill- option to omit empty categories in those with less.

    Comment


    • #3
      Thank you for your assistance, Andrew. The syntax worked out quite well.

      Comment

      Working...
      X