Announcement

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

  • Help with bar chart

    Hi everyone

    I have two variables:
    1. Nutritional status (clas_nut) with the categories 1. underweight, 2. normal, 3. overweight and 4. obese.

    2. Age_group (final_age) with the categories 1.18-34 years, 2.35-54 years and, 3.55 years or more.

    I am trying to make a separate bar chart by age group, then using the combine command put together the graphs by age plus a graph of the nutritional status for the total population. The problem I have is that for the age groups 18-34 and 35-54 I have no underweight subjects, so I only get three bars.

    How can I make the space and the underweight category appear in both graphs?

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(clas_nut edad_final)
    3 1
    3 3
    3 1
    3 1
    4 1
    4 3
    2 3
    2 3
    2 3
    4 2
    2 1
    4 3
    3 3
    3 2
    3 1
    2 1
    2 1
    2 1
    3 1
    4 2
    4 1
    4 2
    2 3
    3 2
    2 2
    3 1
    2 3
    4 3
    4 1
    4 2
    4 2
    2 1
    4 1
    3 3
    4 1
    1 3
    3 1
    4 1
    3 2
    4 2
    4 3
    3 2
    3 3
    3 2
    2 3
    3 3
    4 2
    2 2
    4 2
    2 1
    4 3
    4 2
    3 2
    4 2
    4 2
    3 1
    4 3
    3 2
    4 2
    4 2
    3 2
    4 2
    4 1
    2 3
    3 3
    3 2
    3 2
    4 1
    3 2
    4 3
    4 3
    3 2
    4 3
    4 2
    4 2
    4 2
    4 2
    4 2
    4 3
    3 3
    4 3
    3 1
    3 2
    3 1
    3 2
    3 1
    4 2
    4 1
    3 3
    4 2
    4 2
    3 2
    3 1
    3 1
    3 2
    4 3
    3 2
    3 1
    4 2
    4 3
    end
    label values clas_nut clas
    label def clas 1 "Bajo Peso", modify
    label def clas 2 "Normal", modify
    label def clas 3 "Sobrepeso", modify
    label def clas 4 "Obeso", modify
    label values edad_final eda
    label def eda 1 "18-34 años", modify
    label def eda 2 "35-54 años", modify
    label def eda 3 "55 años o más", modify

  • #2
    Thanks for your data example. You can avoid the problem of empty categories by going straight to a combined graph. Here are two examples using tabplot from the Stata Journal and floatplot from SSC. Naturally many small and large variations are possible.

    Code:
    set scheme s1color 
    
    tabplot clas edad, percent(edad) showval yreverse sep(clas) ///
    bar1(fcolor(blue)) bar2(fcolor(blue*0.2) lcolor(blue)) bar3(fcolor(red*0.2) lcolor(red)) /// 
    bar4(fcolor(red*0.6) lcolor(red)) name(G1, replace) 
    
    floatplot clas, over(edad) highneg(2) fcolors(blue blue*0.2 red*0.2 red*0.6) lcolors(blue blue red red) vertical name(G2, replace)
    Click image for larger version

Name:	obeso_G1.png
Views:	1
Size:	18.9 KB
ID:	1709056
    Click image for larger version

Name:	obeso_G2.png
Views:	1
Size:	18.3 KB
ID:	1709057



    Comment


    • #3
      Hi Nick

      Thank you very much for your help.
      I was unaware of this type of stata charts.
      I thought I should do something more manual.

      Thank you very much again

      Best regards

      Comment

      Working...
      X