Announcement

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

  • catplot command question (adding n=X on bars)

    Hi all,

    I have some very simple code below. Is there a way that I can add an n=some number on each of the bars in my catplot? Thanks -CJ

    catplot gender, percent ytitle(%) title(Gender of Children with Incarcerated Parents) graphregion(color(white))

  • #2
    As repeatedly advised previously, you need to state the provenance of community contributed commands (see FAQ Advice #12). catplot is from SSC, and is a wrapper for the official graph bar. With some effort, you can get what you want using the graph editor, but I will not illustrate that. Using your data from https://www.statalist.org/forums/for...-by-two-groups and the command provided by Nick Cox in #3, consider:

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str63 rmvl_rtrn_rsn1 float inc_parent
    "Adoption"                                                        0
    "Adoption"                                                        1
    "No Data"                                                         0
    "No Data"                                                         0
    "No Data"                                                         0
    "No Data"                                                         0
    "No Data"                                                         0
    "No Data"                                                         0
    "No Data"                                                         0
    "No Data"                                                         0
    "No Data"                                                         0
    "No Data"                                                         0
    "No Data"                                                         0
    "No Data"                                                         0
    "No Data"                                                         0
    "No Data"                                                         1
    "No Data"                                                         1
    "No Data"                                                         1
    "No Data"                                                         1
    "Permanent Legal Custodianship"                                   1
    "Permanent Legal Custodianship"                                   1
    "Permanent Legal Custodianship"                                   1
    "Permanent Placement in the Home of a 'Fit and Willing' Relative" 1
    "Return Home"                                                     0
    "Return Home"                                                     0
    "Return Home"                                                     0
    "Return Home"                                                     0
    "Return Home"                                                     0
    "Return Home"                                                     0
    "Return Home"                                                     0
    "Return Home"                                                     0
    "Return Home"                                                     0
    "Return Home"                                                     0
    "Return Home"                                                     0
    "Return Home"                                                     0
    "Return Home"                                                     0
    "Return Home"                                                     0
    "Return Home"                                                     0
    "Return Home"                                                     0
    "Return Home"                                                     0
    "Return Home"                                                     0
    "Return Home"                                                     0
    "Return Home"                                                     0
    "Return Home"                                                     0
    "Return Home"                                                     0
    "Return Home"                                                     0
    "Return Home"                                                     0
    "Return Home"                                                     0
    "Return Home"                                                     0
    "Return Home"                                                     0
    "Return Home"                                                     0
    "Return Home"                                                     0
    "Return Home"                                                     0
    "Return Home"                                                     0
    "Return Home"                                                     0
    "Return Home"                                                     0
    "Return Home"                                                     0
    "Return Home"                                                     0
    "Return Home"                                                     0
    "Return Home"                                                     0
    "Return Home"                                                     0
    "Return Home"                                                     0
    "Return Home"                                                     0
    "Return Home"                                                     0
    "Return Home"                                                     0
    "Return Home"                                                     0
    "Return Home"                                                     0
    "Return Home"                                                     0
    "Return Home"                                                     0
    "Return Home"                                                     1
    "Return Home"                                                     1
    "Return Home"                                                     1
    "Return Home"                                                     1
    "Return Home"                                                     1
    "Return Home"                                                     1
    "Return Home"                                                     1
    "Return Home"                                                     1
    "Return Home"                                                     1
    "Return Home"                                                     1
    "Return Home"                                                     1
    "Return Home"                                                     1
    "Return Home"                                                     1
    "Return Home"                                                     1
    "Return Home"                                                     1
    "Return Home"                                                     1
    "Return Home"                                                     1
    "Return Home"                                                     1
    "Return Home"                                                     1
    "Return Home"                                                     1
    "Return Home"                                                     1
    "Return Home"                                                     1
    "Return Home"                                                     1
    "Return Home"                                                     1
    "Youth is 18+ and No Affidavit/Conciliation"                      0
    "Youth is 18+ and No Affidavit/Conciliation"                      0
    "Youth is 18+ and No Affidavit/Conciliation"                      0
    "Youth is 18+ and No Affidavit/Conciliation"                      0
    "Youth is 18+ and No Affidavit/Conciliation"                      0
    "Youth is 18+ and No Affidavit/Conciliation"                      1
    "Youth is 18+ and No Affidavit/Conciliation"                      1
    end
    
    gen cat = ustrregexra(rmvl_rtrn_rsn1, "(\w+\s\w+)\s.*", "$1")
    bys cat inc_parent: gen count=_N
    replace cat= cat + " ({it:n =} " + string(count)+")"
    set scheme s1color
    catplot inc_parent cat, asyvars bar(2, color(red)) bar(1, color(blue))
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	57.6 KB
ID:	1683120

    Comment

    Working...
    X