Announcement

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

  • Multiple catplot graphs in one

    Dear all,

    I have two categorical variables, which have exactly the same categories. I want to graph them over two binary variables. To do so I am using catplot from SSC. I can to this separately for each categorical variable. Ideally I would like to have a single graph, where the first categorical variable appears as bar and the second as a dot.

    Here is an extract from my dataset and the catplot commands I use.

    Kind regards,
    Nikos


    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input double(pw y) float(group0 group1 p)
    1.0701686855937376 2 0 0 .
    1.2769962412465246 3 0 0 3
     .7020298824594472 3 0 0 3
    2.5763142027304737 4 0 0 .
     .7319357611193447 3 0 0 .
     1.551785459656731 3 0 0 .
      3.91013046588809 2 0 0 .
     1.060711759065474 4 0 0 .
     .8509393770698431 1 0 1 .
     .2747122687191739 3 0 0 3
     .8740380276029754 4 0 0 .
    2.8192703492058295 2 0 0 .
     .8643545532312645 3 0 0 .
     .8930920160624967 3 0 0 .
     .8161582556242973 4 0 0 .
     .5892249313578158 1 0 0 .
     .9949340932935794 3 0 0 .
     .9654764165230842 4 0 0 3
     .7478367804955939 3 0 0 1
    1.0952558210770287 4 0 0 4
     .8757173799166524 2 0 0 4
     1.060711759065474 3 0 0 4
     .9856762712807583 4 0 0 3
     .3437688862664291 4 0 0 .
     1.551785459656731 4 0 0 3
     1.531744757434929 3 0 0 .
    1.2162728684073763 3 0 0 .
     .7370770909603899 3 0 0 3
    .23920157242153414 4 0 1 4
     .7722673640220348 4 0 0 .
     3.387787469641178 3 0 1 2
     .7922394078517215 4 0 0 .
     .9486613870337038 3 0 0 .
     3.387787469641178 4 0 0 .
     .8496864250664132 4 0 0 3
     .8509393770698431 4 0 0 4
     2.887040100976666 2 0 0 .
     .6717964891427893 3 0 1 .
    3.6492112781403137 3 0 0 .
     .7478367804955939 3 0 0 .
     .9431867198658732 3 0 0 .
     .3192677572197027 3 0 0 3
     .8284133058274891 4 0 0 .
     .7922394078517215 3 0 0 3
    .31479248932951504 4 0 0 .
     .9431867198658732 3 0 1 .
     .8284133058274891 2 0 0 4
     .8026936509706939 3 0 0 .
    .27043763427379386 4 0 0 .
     .6693414425328248 3 0 0 .
      .649449982166785 3 0 0 3
    1.3049688486805289 4 0 0 4
    .31479248932951504 3 0 0 .
     .6814637210062828 4 0 0 4
    1.6832255042232853 2 0 0 .
    1.0834064224887905 3 0 0 .
     .8930920160624967 3 0 0 .
     .8736987405358949 3 0 0 4
    1.0360594347885617 4 0 0 .
      .890480426314452 3 0 0 3
    1.0168907074070914 4 0 0 4
     .8892019805728717 3 0 0 .
    1.1031198652560092 3 0 0 3
     3.355357400523641 3 0 0 .
    1.1772648810420092 4 0 0 1
     .6783066171626717 3 0 0 .
    1.3649042775178337 2 0 0 2
     .9498158809669293 3 0 0 4
      .428075426755009 2 0 0 4
     .7281079363132699 4 0 0 4
    1.2379720187232846 3 0 0 3
     .9431867198658732 4 0 0 3
     .8740380276029754 3 0 0 3
     .8624784527929937 2 0 0 3
     .8624784527929937 4 0 0 3
    1.3334380042979188 3 0 0 .
     2.686569320246718 2 0 0 .
     1.012520472589917 3 0 0 .
     .5693241765161087 3 0 0 3
     .5892249313578158 3 0 0 .
     .9693457796522157 3 0 0 3
     .6910587277035091 2 0 0 2
     .7445792112054933 3 0 0 .
     .5779031926894344 3 0 0 .
     .8161582556242973 4 0 0 .
    1.2115440494368466 4 0 0 .
     .8911076840924655 4 0 0 3
     .8086378167685316 4 0 0 .
    1.6179905041805953 1 0 0 .
      .890480426314452 3 0 0 .
    1.6635614929109364 1 0 0 .
    .28056165994757726 3 0 0 .
     .5618035531875011 3 0 0 2
    1.1484208427050198 4 0 0 .
     .8911076840924655 3 0 0 .
     .8996549159312841 4 0 0 .
     .7020298824594472 3 0 0 .
     .7798331933826009 3 0 0 .
    .46038833057547657 3 0 0 .
     .8757173799166524 3 0 0 .
    1.0718793088104661 3 0 0 .
    1.2115440494368466 3 0 0 4
     .9365270443201292 3 0 0 .
     .8812798825498497 4 0 0 .
     .7445792112054933 4 0 0 .
     .9046264847449188 4 0 0 .
     .6717964891427893 3 0 0 4
     .6910587277035091 1 0 0 3
     1.233643552958086 3 0 1 .
      .614312100096655 3 0 0 .
    .41105231844101303 2 0 0 1
     .7608047261912579 4 0 0 .
    1.3287443143538615 3 0 0 .
    1.3649042775178337 4 0 0 3
     .3682227213110534 2 0 0 .
     .7361817085704142 4 0 0 .
     .9228678690359587 3 0 0 4
     .7614034551551341 3 0 0 3
    1.2162728684073763 3 0 0 4
    2.7912260802342246 3 0 0 4
     .5752488597759113 3 1 0 4
     .7534450131871867 2 1 0 .
    1.1974800842879416 3 1 0 4
    3.5112844495184574 4 1 1 .
     .5365981899951895 3 1 0 .
     .6167486625306939 4 1 0 .
                     4 4 1 1 .
     .8990132594015768 3 1 0 .
     .8990132594015768 2 1 0 .
     .5700283570856395 3 1 0 3
    3.0334311577374318 1 1 0 .
    1.5370155440914004 3 1 1 .
    1.7451928720551306 2 1 1 .
     .3734830572684379 3 1 1 .
    .28269212190052373 3 1 1 4
     .8351249193291597 3 1 0 .
    1.5982623266126246 3 1 0 .
     .5700283570856395 3 1 0 4
     .5365981899951895 4 1 0 .
     .5761502909819258 4 1 1 .
     .5365981899951895 4 1 0 .
     .5365981899951895 3 1 0 .
    1.5982623266126246 3 1 0 .
     .7564505206354993 2 1 0 .
     .5700283570856395 3 1 0 .
    1.5951426625773988 4 1 0 4
     .3946856371864086 4 1 0 .
     2.005876911658901 4 1 0 .
     .8050326023850026 3 1 0 3
     .5365981899951895 4 1 0 .
     .7564505206354993 3 1 1 .
    1.5982623266126246 2 1 0 .
     .8426412126949698 3 1 1 .
     .6167486625306939 3 1 0 .
     .4158337494444011 4 1 1 3
     .3946856371864086 4 1 0 .
     .5800604382600965 3 1 0 .
     .7196778361030018 3 1 0 .
     .5700283570856395 3 1 0 .
     .5365981899951895 2 1 0 .
    2.0688945146463062 4 1 0 4
     .5700283570856395 2 1 0 .
     .3734830572684379 3 1 0 .
     1.059417814530797 2 1 1 .
      .549393331059358 3 1 1 .
     .7552143303481247 4 1 0 .
    1.5343300975790268 4 1 0 4
     .7196778361030018 4 1 0 .
     2.005876911658901 4 1 0 .
    1.5982623266126246 4 1 0 .
      .662126681784222 4 1 0 .
     .5700283570856395 4 1 0 .
     .9917034005161637 3 1 0 4
     .6167486625306939 3 1 0 .
     .6167486625306939 3 1 0 .
     .8426412126949698 4 1 0 4
    2.0688945146463062 3 1 1 4
    2.3313450197783347 4 1 0 .
     .5800604382600965 3 1 0 .
    1.4334207874618656 3 1 0 .
     .5700283570856395 3 1 0 4
     .5365981899951895 2 1 0 .
     .8426412126949698 3 1 1 .
     .5800604382600965 3 1 0 .
     2.684380722740627 3 1 1 .
    1.5982623266126246 3 1 1 .
     .5700283570856395 1 1 0 .
     .9917034005161637 3 1 0 .
    1.5982623266126246 3 1 0 2
     1.724252489530963 4 1 0 .
    2.0107263877948736 4 1 0 4
     .7534450131871867 4 1 1 .
    .49566042554901874 4 1 0 .
     .3946856371864086 4 1 1 .
     1.059417814530797 3 1 0 .
     2.005876911658901 2 1 0 3
     .6167486625306939 4 1 0 4
     2.337326457598415 4 1 0 .
     .9917034005161637 4 1 0 .
     2.005876911658901 3 1 0 .
     .9917034005161637 2 1 0 .
    end
    label values y yl
    label values p yl
    label def yl 1 "Strongly disagree", modify
    label def yl 2 "Somewhat disagree", modify
    label def yl 3 "Somewhat agree", modify
    label def yl 4 "Strongly agree", modify
    Code:
    catplot group0 y group1 [aw=pw] if p ! = . , percent(group1 group0) blabel(bar, position(outside) format(%3.1f))
    catplot group0 p group1 [aw=pw] if p ! = . , percent(group1 group0) blabel(bar, position(outside) format(%3.1f))



  • #2
    Starting off your data example, try something like this:

    Code:
    label values y yl
    label values p yl
    label def yl 1 "Strongly disagree", modify
    label def yl 2 "Somewhat disagree", modify
    label def yl 3 "Somewhat agree", modify
    label def yl 4 "Strongly agree", modify
    
    local opts percent(group1 group0) blabel(bar, position(outside) format(%3.1f))
    drop if missing(p) 
    catplot group0 y group1 [aw=pw] , `opts' name(G1, replace) 
    catplot group0 p group1 [aw=pw] , `opts' name(G2, replace) 
    
    rename (y p) (y1 y2) 
    gen id = _n 
    reshape long y, i(id) 
    
    label def _j 1 y 2 p 
    label val _j _j 
    
    catplot group0 y group1 [aw=pw], by(_j, note(""))  percent(_j group1 group0) blabel(bar, position(outside) format(%3.1f))
    followed if desired by some excision in the Graph Editor.

    Comment


    • #3
      Dear Nick,

      thanks you very much for the work around.

      Comment

      Working...
      X