Announcement

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

  • Fixing bar cart legend

    Hello statalist community, I am trying to graph a bar chart for labor force participation by sex across different countries in different years.
    This is the code I am using :
    graph bar (mean) crlfsr1 if age >= 15 & age <= 64, over(sex) over(country_year) legend(on)
    However the legend doesn't generate for the sex and the graph appears like this:
    Click image for larger version

Name:	Screenshot (123).png
Views:	1
Size:	45.0 KB
ID:	1738678



    Any idea How I can fix the code so that the legend displays gender rather than mean of crlfsr1?
    Thank you.
    Attached Files

  • #2
    You probably want the option -asyvars-. See

    Code:
    help graph bar
    Code:
    graph bar (mean) crlfsr1 if age >= 15 & age <= 64, over(sex) over(country_year) asyvars legend(on)

    Comment


    • #3
      Thank you sir, this worked perfectly. I have an issue with another graph, it's really simple but I am not sure why it's not working properly. I want to generate a line graph that represents the mean of crlsfr1 over ages and sex. I can do it as a bar chart, I attached as a reference but It's not working as line.
      Click image for larger version

Name:	Screenshot (124).png
Views:	1
Size:	72.4 KB
ID:	1738683

      Comment


      • #4
        If you have multiple observations per time-period, you need to aggregate the data. collapse will create period means.

        Code:
        webuse grunfeld, clear
        qui sum mvalue, d
        gen smallcap=mvalue< r(p50)
        collapse invest, by(smallcap year)
        tw line invest year if smallcap, sort|| line invest year if !smallcap, sort||, leg(order(1 "Small-Cap" 2 "Large-Cap")) xtitle("")
        Click image for larger version

Name:	Graph.png
Views:	1
Size:	42.1 KB
ID:	1738694

        Last edited by Andrew Musau; 02 Jan 2024, 15:29.

        Comment


        • #5
          Trivia time. EGY-O6 should presumably be EGY-06, as code for Egypt in 2006.

          Comment


          • #6
            Thank you all for the help.

            Comment

            Working...
            X