Announcement

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

  • Stata 17: Relabel Graphs with Smaller Font Size in Survey Data

    Dear Statalist Users,

    I have a quick question to ask you please:

    I am trying to reduce the font size of my x-axis labels. Nevertheless, I am struggling to do it. Basically, that's my code:

    Code:
    graph bar (mean) sexe1 sexe2 [pw = k_gewicht],                               ///
          over(bachelor_hes, relabel(1 "Autres Formations"                    ///
          2 "Bachelor HES-SO sans GE" 3 "Bachelor HES-GE" 4          ///
          "Autres Bachelors HES",labsize(small)))                                 ///
          legend(label(1 "Homme") label(2 "Femme"))                               ///
          percentages bargap(-10)                                                             ///
          ytitle("en pourcent (%)")                                                              ///
          bar(1, color(pink))                                                                       ///
          bar(2, color(ltblue))                                                                     ///
          title("Diplômes obtenus (moyenne pondérée)")                         ///
          subtitle("Par sexe")                                                                    ///
          note("Source : {&copy} Haute École de Gestion de Genève. Données : OFS, 2022")

    Does anyone could help me please ?

    I thank you in advance for your help.

    Best Regards,

    --
    Michael Duarte Gonçalves


  • #2
    I can’t see your graph but my advice starts with try

    Code:
    graph hbar

    Comment


    • #3
      Dear Professor Cox,

      Thank you very much for your answer.
      I am a real fan of your work and try to apply the advice given in your paper "Suggestions on Stata programming style" (2005).

      I tried using graph hbar instead of graph bar, and the result is the same. Here is the error code given:

      Code:
      option labels() incorrectly specified
              expects, # "label" # label ...  r(198);
      
      end of do-file
      Here is the graph that I obtained. My aim is to reduce the font size of the labels under the vertical bars precisely by using code, and without having to fiddle with the editor available when creating the graphics.



      Click image for larger version

Name:	Graph.png
Views:	1
Size:	35.9 KB
ID:	1687724




      Thank you in advance for your help. Thank you for your patience.


      Yours faithfully,

      --
      Michael Duarte Gonçalves

      Comment


      • #4
        Thanks for the appreciation, but I can't see how the graph in #3 could be the result of graph hbar.

        You are just showing 4 percents, as % Homme = 100 - % Femme, so this code is to show that readable text is perfectly possible with graph hbar. Blue for male, pink for female, or are trying to subvert expectations?

        Showing 50% as a reference level might be tempting.

        Code:
        clear
        input pchomme which
        36 1
        42 2
        44 3
        54 4
        end
        
        label def which 1 "Autres Formations"
        label def which 2 "Bachelor HES-SO sans GE", add
        label def which 3 "Bachelor HES-GE", add
        label def which 4 "Autres Bachelors HES", add
        
        label val which  which
        
        set scheme s1color
        graph hbar (asis) pchomme, ytitle("pourcent Homme (%)") bar(1, color(ltblue)) ///                                                                   ///
        over(which) title("Diplômes obtenus (moyenne pondérée)")   ysc(alt)     ///
        note("Source : {&copy} Haute École de Gestion de Genève. Données : OFS, 2022")
        Click image for larger version

Name:	duarte.png
Views:	1
Size:	28.1 KB
ID:	1687744

        Comment


        • #5
          Dear Professor Cox,

          Thank for the suggestion ! Everything is clear now.

          Best regards,

          --
          Michael Duarte Gonçalves

          Comment

          Working...
          X