Announcement

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

  • How to display xlabel in a vertical way?

    Good morning to the community.
    I have xlabel with (Basic Materials, Communications, ConsumerCyclical ...) and I would like to apply a vertical angle to this xlabels.
    Code:
    twoway scatter ln_firm_performance industry_n, msymbol(circle_hollow) || connected ln_firm_performance_mean industry_n, msymbol(diamond) || , xlabel(1 "Basic Materials" 2 "Communications" 3 "Consumer, Cyclical" 4 "Consumer, Non-Cyclical" 5 "Energy" 6 "Financial" 7 "Industrial" 8 "Technology" 9 "Utilities", labsize(small), ang(v)))
    I have the error ivalid 'ang' r(198) mentioned when I run the command.

    Thank you for your help.

    Lucas BORDURE
    Student MSc. in International Finance
    Rennes School of Business
    Stata SE 16.1

  • #2
    The syntax has got tangled there. I imagine you intended something more like


    Code:
    twoway scatter ln_firm_performance industry_n, msymbol(circle_hollow) ///
    connected ln_firm_performance_mean industry_n, msymbol(diamond)    ///  
    xlabel(1 "Basic Materials" 2 "Communications" 3 "Consumer, Cyclical"  ///
    4 "Consumer, Non-Cyclical" 5 "Energy" 6 "Financial" 7 "Industrial" 8 "Technology" 9 "Utilities", labsize(small), ang(v))
    To show distributions over categories, together with their means, consider this different example using stripplot from SSC.


    Code:
    sysuse auto, clear
    label def rep78 1 `" "evidently" "appalling" "' 2 `" "evidently" "bad" "' 3 `" "evidently" "competent" "' 4 `" "evidently" "desirable" "' 5 `" "evidently" "excellent" "'
    label val rep78 rep78
    stripplot price, over(rep78) cumul cumprob vertical refline center xsc(titlegap(*5)) xla(, noticks) mc(blue)
    Click image for larger version

Name:	stripplot.png
Views:	1
Size:	31.4 KB
ID:	1613144




    Your data is evidently performance on log scale. That doesn't bite.

    Vertical angle x axis labels are allowed but just about the worst possible solution for long labels, leading to giraffe graphics. You can make progress by stacking text on two or more levels.

    A quantile plot is likely to be clearer than a plain scatter plot (one-dimensional dot or strip plot) for showing the distribution of your measure in each industry. That remains true even if you have many more data points than in my example.

    Why connect the means when the axis is categorical and indeed the order is just alphabetical? (Re-ordering the categories might make sense.)

    Comment


    • #3
      Thank you for your answer Nick Cox. I'm using Stata SE 16.1.
      Question 1: What is the name of the syntax between inverted commas and 1?
      Code:
       
       1 `"
      Question 2: Why I get the error label industry_n already defined? (r110) when I run the command?
      Code:
      label def industry_n 1 `" "Basic" "Materials" "' 2 `" "Communications" 3 `" "Consumer" "Cyclical" "' 4 `" "Consumer" "Non-Cyclical" "' 5 `" "Energy" 6 `" "Financial" 6 `" "Industrial" 7 `" "Technology" 8 `" "Utilities" 
      label val industry_n industry_n
      stripplot ln_firm_performance, over(industry_n) cumul cumprob vertical refline center xsc(titlegap(*5)) xla(, noticks) mc(blue)
      I understand the added value of the single program package named stripplot. I think I need to use it.






      Attached Files

      Lucas BORDURE
      Student MSc. in International Finance
      Rennes School of Business
      Stata SE 16.1

      Comment


      • #4
        Q1. Compound double quotes.

        Q2. See

        Code:
        help label
        In your case, but not mine, you need the modify option on label val.

        On re-ordering making more sense, see https://www.statalist.org/forums/for...e-or-graph-use

        Comment


        • #5
          I understand the syntax label def.
          But on the command "help label", the syntax label val is not explained. I don't know what is representing the syntax label val.

          Question: Why are you writing two times rep 78 ? Why you don't use the modifiy option?
          Code:
           label val rep78 rep78

          Lucas BORDURE
          Student MSc. in International Finance
          Rennes School of Business
          Stata SE 16.1

          Comment


          • #6
            Sorry, I didn't mean what I said. The modify belongs on label define.,

            In label val you need a variable name and a label name -- which may be, but need not be, identical.

            Comment


            • #7
              I defined the label type_industry like this:
              Code:
              label def type_industry `" "Basic" "Materials" "' 2 `" "Communications" 3 `" "Consumer" "Cyclical" "' 4 `" "Consumer" "Non-Cyclical" "' 5 `" "Energy" 6 `" "Financial" 7 `" "Industrial" 8 `" "Technology" 9 `" "Utilities", modify

              but I get the error r(198) invalid syntax.
              What is the good syntax when I have sometimes words which need to be stacked and sometimes words which don't need to be stacked?


              And then i defined the label label val like this:
              Code:
              label val type_industry type_industry
              .
              Does
              label val need to be the same label as label def?

              Lucas BORDURE
              Student MSc. in International Finance
              Rennes School of Business
              Stata SE 16.1

              Comment


              • #8
                Look again. First you missed out
                Code:
                1
                .

                Every time you put down

                Code:
                `"
                it's a promise to put down a matching

                Code:
                "'
                and you did not do that for values 2 5 6 7 8 or 9. So 3 and 4 have good definitions.



                Code:
                 label def type_industry 1 `" "Basic" "Materials" "'  ///
                2 `" "Communications" "' 3 `" "Consumer" "Cyclical" "' 4 `" "Consumer" "Non-Cyclical" "' ///
                5 `" "Energy" "' 6 `" "Financial" "' 7 `" "Industrial" 8 `" "Technology" 9 `" "Utilities", modify

                Comment


                • #9
                  Thank you for this editing concerning the errors in this part of the code .

                  Despite your help, I face with a new problem.

                  When I run this command:

                  Code:
                  ssc install outreg
                  label def type_industry 1 `" "Basic" "Materials" "'  ///
                  2 `" "Communications" "' 3 `" "Consumer" "Cyclical" "' 4 `" "Consumer" "Non-Cyclical" "' ///
                  5 `" "Energy" "' 6 `" "Financial" "' 7 `" "Industrial" 8 `" "Technology" 9 `" "Utilities", modify
                  label val industry_n industry_n
                  stripplot ln_firm_performance, over(industry_n) cumul cumprob vertical refline center xsc(titlegap(*5)) xla(, noticks) mc(blue)
                  I've got the error command stripplot is unrecognized. (r199)

                  Lucas BORDURE
                  Student MSc. in International Finance
                  Rennes School of Business
                  Stata SE 16.1

                  Comment


                  • #10
                    As mentioned in #2 stripplot is from SSC, so you must install it before you can use it.


                    Code:
                    ssc install stripplot

                    Comment


                    • #11
                      Click image for larger version

Name:	Capture.PNG
Views:	1
Size:	86.2 KB
ID:	1613270
                      Thank you, it's working more and more. But the xlabel doesn't want to be stacked in levels.
                      Last edited by Lucas Bordure; 05 Jun 2021, 01:09.

                      Lucas BORDURE
                      Student MSc. in International Finance
                      Rennes School of Business
                      Stata SE 16.1

                      Comment


                      • #12
                        Please copy and paste the command you used.

                        Here are some revised suggestions.


                        1. "Communications" is the most problematic label.

                        2. I suggest plotting performance on a log scale, not log performance.

                        3. Your use of mean of log performance corresponds to geometric mean of performance.

                        4. I suggest ordering by geometric mean, not alphabetically.

                        5. The installation commands are commented out, but remove the * if you need to install anything.

                        6. Don't use the default scheme s2color unless you like it.


                        Code:
                        clear
                        set obs 900
                        set seed 2803
                        
                        gen performance = exp(rnormal(-2, 1))
                        gen type_industry = ceil(_n/ 100)
                        
                        label def type_industry 1 `" "Basic" "Materials" "'  ///
                        2  `" "Communi-" "cations" "' 3 `" "Consumer" "Cyclical" "' 4 `" "Consumer" "Non-Cyclical" "' ///
                        5  "Energy"  6 "Financial"  7 "Industrial"  8 "Technology" 9  "Utilities" , modify
                        
                        label val type_industry type_industry
                        
                        * get a gmean() function (don't remove the *) 
                        * ssc inst egenmore
                        
                        * sort on geometric mean (don't remove the *) 
                        * ssc inst myaxis
                        myaxis xaxis=type_industry, sort(gmean performance)
                        
                        * ssc inst stripplot
                        stripplot performance, over(xaxis) centre vertical cumul cumprob refline scheme(s1color) xla(, noticks labsize(small)) xsize(7) xtitle("") ysc(log) yla(5 2 1 0.5 0.2 0.1 0.05 0.02, ang(h))  reflevel(gmean) mc(blue)
                        Click image for larger version

Name:	performance.png
Views:	1
Size:	60.7 KB
ID:	1613274

                        Last edited by Nick Cox; 05 Jun 2021, 02:34.

                        Comment


                        • #13
                          Good afternoon!
                          I faced with errors so I changed your code.

                          Substitution 1:
                          Code:
                          set obs 900
                          becomes
                          Code:
                          set obs 1322
                          Substitution 2:
                          Code:
                          xsize(7)
                          becomes
                          Code:
                          xsize(15)
                          Concerning egenmore and myaxis packages:
                          I put the following packages without * as you explained.
                          Code:
                          ssc inst egenmore
                          ssc inst myaxis
                          The entire code becomes:
                          Code:
                          ssc inst egenmore
                          ssc inst myaxis
                          set obs 1322
                          set seed 2803
                          gen performance = exp(rnormal(-2, 1))
                          gen type_industry = ceil(_n/ 100)
                          label def type_industry 1 `" "Basic" "Materials" "'  ///
                          2  `" "Communi-" "cations" "' 3 `" "Consumer" "Cyclical" "' 4 `" "Consumer" "Non-Cyclical" "' ///
                          5  "Energy"  6 "Financial"  7 "Industrial"  8 "Technology" 9  "Utilities" , modify
                          label val type_industry type_industry
                          * get a gmean() function (don't remove the *) 
                          *ssc inst egenmore
                          * sort on geometric mean (don't remove the *) 
                          *ssc inst myaxis
                          myaxis xaxis=type_industry, sort(gmean performance)
                          * ssc inst stripplot
                          stripplot performance, over(xaxis) centre vertical cumul cumprob refline scheme(s1color) xla(, noticks labsize(small)) xsize(15) xtitle("") ysc(log) yla(5 2 1 0.5 0.2 0.1 0.05 0.02, ang(h))  reflevel(gmean) mc(blue)
                          But my graph does not have the same design as the graphic above (previous comment).

                          Click image for larger version

Name:	Capture.PNG
Views:	1
Size:	44.8 KB
ID:	1613311


                          + Size of xlabel is good.
                          - xlabel have been added



                          Lucas BORDURE
                          Student MSc. in International Finance
                          Rennes School of Business
                          Stata SE 16.1

                          Comment


                          • #14
                            I think the origin of the problem is:
                            Code:
                            set obs 900
                            .
                            When I run the code you have written previously, I have the error observation number out of range
                            Observation number must be between 1,321 and 2,147,483,619. (Observation numbers are typed without commas.) (r 198).

                            Lucas BORDURE
                            Student MSc. in International Finance
                            Rennes School of Business
                            Stata SE 16.1

                            Comment


                            • #15
                              Sorry, your code it is working perfectly.

                              Code:
                              clear
                              set obs 900
                              set seed 2803
                              
                              gen performance = exp(rnormal(-2, 1))
                              gen type_industry = ceil(_n/ 100)
                              
                              label def type_industry 1 `" "Basic" "Materials" "'  ///
                              2  `" "Communi-" "cations" "' 3 `" "Consumer" "Cyclical" "' 4 `" "Consumer" "Non-Cyclical" "' ///
                              5  "Energy"  6 "Financial"  7 "Industrial"  8 "Technology" 9  "Utilities" , modify
                              
                              label val type_industry type_industry
                              
                              * get a gmean() function (don't remove the *) 
                              * ssc inst egenmore
                              
                              * sort on geometric mean (don't remove the *) 
                              * ssc inst myaxis
                              myaxis xaxis=type_industry, sort(gmean performance)
                              
                              * ssc inst stripplot
                              stripplot performance, over(xaxis) centre vertical cumul cumprob refline scheme(s1color) xla(, noticks labsize(small)) xsize(7) xtitle("") ysc(log) yla(5 2 1 0.5 0.2 0.1 0.05 0.02, ang(h))  reflevel(gmean) mc(blue)

                              Thank you a lot.

                              Lucas BORDURE
                              Student MSc. in International Finance
                              Rennes School of Business
                              Stata SE 16.1

                              Comment

                              Working...
                              X