Announcement

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

  • Include a note in a combined graph

    Hi,
    I am using a user written command catplot in Stata 18 and would like to include a note "Prefer not to answer recoded to missing" in graph comprising of combined graphs.
    My example dataset is
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input byte(id resp_1 resp_2 resp_3) float weight
     1 1 1 1 1.7
     2 2 2 2 2.3
     3 2 3 3 3.1
     4 3 1 1 1.2
     5 1 1 2 1.5
     6 3 2 3 5.4
     7 2 3 2 3.7
     8 1 2 2 2.6
     9 3 3 2 9.4
    10 1 3 2 4.9
    11 1 3 3 4.8
    12 1 3 2 5.2
    13 1 3 1 3.7
    14 1 2 1 3.1
    15 3 1 2 3.4
    16 2 3 1 5.6
    17 3 3 1 6.7
    18 3 1 2 8.9
    19 3 2 3 2.4
    20 2 3 3 3.6
    21 2 1 2 4.9
    22 3 2 2 5.1
    23 1 3 1 2.3
    24 1 3 2 1.5
    25 1 2 3 2.8
    26 2 1 1 3.9
    27 3 1 2 4.6
    28 3 2 3 4.9
    29 1 3 3 2.5
    30 1 3 2 2.8
    31 1 3 1 3.2
    32 2 3 1 3.7
    33 3 1 2 9.1
    34 1 2 1 1.2
    35 2 3 1 1.7
    36 3 1 2 2.8
    37 2 2 2 3.6
    38 2 2 3 6.5
    39 2 2 2 1.5
    40 2 2 3 1.7
    41 1 1 2 1.8
    42 1 2 2 2.8
    43 2 3 2 2.6
    44 3 1 2 4.3
    45 3 2 3 6.3
    46 2 3 1 9.7
    47 1 3 1 5.4
    48 2 3 2 8.1
    49 2 3 3 2.3
    50 2 3 2 3.7
    end
    label values resp_1 resp
    label values resp_2 resp
    label values resp_3 resp
    label def resp 1 "Less than 40%", modify
    label def resp 2 "50% - 70%", modify
    label def resp 3 "More than 70%", modify
    and my code is
    Code:
    catplot resp_1 [aweight = weight], blabel(bar, format(%3.0f)) l1title("") title("") ytitle("Percent") b1title("") percent recast(bar) name(g1, replace)
    
    catplot resp_2 [aweight = weight], blabel(bar, format(%3.0f)) l1title("") title("") ytitle("Percent") b1title("") percent recast(bar) name(g2, replace)
    
    catplot resp_3 [aweight = weight], blabel(bar, format(%3.0f)) l1title("") title("") ytitle("Percent") b1title("") percent recast(bar) name(g3, replace)
    
    graph combine g1 g2 g3
    Any help will be appreciated. Thank you!
    Last edited by Stephen Okiya; 02 Mar 2024, 09:22.

  • #2
    catplot is from SSC. (You are asked to say where community-contributed commands come from.)

    Why not put the graphs together as one plot directly without combining? Here is a take using tabplot from the Stata Journal.

    You could subdivide with different colours.

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input byte(id resp_1 resp_2 resp_3) float weight
     1 1 1 1 1.7
     2 2 2 2 2.3
     3 2 3 3 3.1
     4 3 1 1 1.2
     5 1 1 2 1.5
     6 3 2 3 5.4
     7 2 3 2 3.7
     8 1 2 2 2.6
     9 3 3 2 9.4
    10 1 3 2 4.9
    11 1 3 3 4.8
    12 1 3 2 5.2
    13 1 3 1 3.7
    14 1 2 1 3.1
    15 3 1 2 3.4
    16 2 3 1 5.6
    17 3 3 1 6.7
    18 3 1 2 8.9
    19 3 2 3 2.4
    20 2 3 3 3.6
    21 2 1 2 4.9
    22 3 2 2 5.1
    23 1 3 1 2.3
    24 1 3 2 1.5
    25 1 2 3 2.8
    26 2 1 1 3.9
    27 3 1 2 4.6
    28 3 2 3 4.9
    29 1 3 3 2.5
    30 1 3 2 2.8
    31 1 3 1 3.2
    32 2 3 1 3.7
    33 3 1 2 9.1
    34 1 2 1 1.2
    35 2 3 1 1.7
    36 3 1 2 2.8
    37 2 2 2 3.6
    38 2 2 3 6.5
    39 2 2 2 1.5
    40 2 2 3 1.7
    41 1 1 2 1.8
    42 1 2 2 2.8
    43 2 3 2 2.6
    44 3 1 2 4.3
    45 3 2 3 6.3
    46 2 3 1 9.7
    47 1 3 1 5.4
    48 2 3 2 8.1
    49 2 3 3 2.3
    50 2 3 2 3.7
    end
    label values resp_1 resp
    label values resp_2 resp
    label values resp_3 resp
    label def resp 1 "Less than 40%", modify
    label def resp 2 "50% - 70%", modify
    label def resp 3 "More than 70%", modify
    
    reshape long resp_, i(id) j(which)
    
    tabplot which resp_ [aw=weight], percent(which) showval(format(%3.0f)) xtitle(Something here) ytitle(Something there) ///
    note(Prefer not to answer recoded to missing) subtitle(%)
    Click image for larger version

Name:	tabnotcatplot.png
Views:	1
Size:	39.5 KB
ID:	1745294

    Last edited by Nick Cox; 02 Mar 2024, 09:57.

    Comment

    Working...
    X