Announcement

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

  • Bar chart labelling problem for categorical variables

    Hi, I used the following code to create a stacked bar chart and it works very well (see the picture attached).

    Code:
    graph hbar (percent), over(tradition_family_group) over (sex) asyvars percentages stack ///
    blabel(bar, pos(center) format(%3.1f)) ytitle("Percentages") title("Family value by sex") subtitle(" ")
    However, I would like to relabel the "0" and "1" on the vertical axis as "female" and "male" using the following code:

    Code:
    graph hbar (percent), over(tradition_family_group) over (sex, relabel(1 "Female" 2 "Male") ) ///
    asyvars percentages stack blabel(bar, pos(center) format(%3.1f)) ytitle("Percentages") title("Family value by sex") ///
    subtitle(" ")
    I saw the following error:

    Code:
    ) required
    r(100);
    
    end of do-file
    
    r(100);
    Could you let me know what's the problem? Thank you very much.
    Attached Files

  • #2
    Eliminate the space between over and the opening parenthesis in the second -over()- option.

    Code:
    graph hbar (percent), over(tradition_family_group) over(sex, relabel(1 "Female" 2 "Male") ) ///
    asyvars percentages stack blabel(bar, pos(center) format(%3.1f)) ytitle("Percentages") title("Family value by sex") ///
    subtitle(" ")

    Comment


    • #3
      Originally posted by Andrew Musau View Post
      Eliminate the space between over and the opening parenthesis in the second -over()- option.

      Code:
      graph hbar (percent), over(tradition_family_group) over(sex, relabel(1 "Female" 2 "Male") ) ///
      asyvars percentages stack blabel(bar, pos(center) format(%3.1f)) ytitle("Percentages") title("Family value by sex") ///
      subtitle(" ")
      Thank you so much. It's soooo weird!

      Comment

      Working...
      X