Announcement

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

  • bar graph

    Dear All, Suppose that I have this data set:
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str63 Journal_e float IF1_omega_w1
    "International Economic Review"                                    .238486
    "The Journal of World Economy"                                   .20098802
    "China Rural Survey"                                             .09736695
    "Modern Economic Science"                                       .072677195
    "Researches in Chinese Economic History"                         .04450123
    "Economic Research Journal"                                      .03934519
    "The Journal of Quantitative & Technical Economics"              .03745284
    "Zhejiang Finance"                                               .03477633
    "Tourism Science"                                               .029117016
    "Ancient and Modern Agriculture"                                 .02865064
    "World Economy Studies"                                          .02840467
    "Scientific and Technological Management of Land and Resources"  .02704981
    "Finance & Trade Economics"                                      .02460474
    "Tourism Tribune"                                               .021358477
    "Economic Theory and Business Management"                       .019578734
    "Journal of Beijing Forestry University"                        .016145939
    "Chinese Rural Economy"                                         .011040545
    "Journal of Shanghai University of Finance and Economics"       .009785404
    "Economic Review"                                               .007974063
    "Value Engineering"                                             .005818428
    end
    I'd like to draw a bar graph. However, The names of Journals (Journal_e) are long. Any suggestions? Thanks.
    Ho-Chuan (River) Huang
    Stata 19.0, MP(4)

  • #2
    PS: For the bar graph, the names of Journals (Journal_e) are on the y-axis, and the weights (IF1_omega_w1) are the corresponding bar lengths.
    Last edited by River Huang; 30 Jul 2022, 21:02.
    Ho-Chuan (River) Huang
    Stata 19.0, MP(4)

    Comment


    • #3
      You just have to abbreviate as many words as possible, unless your audience is specialized and understands, e.g., JEL is Journal of Economic Literature and AER is American Economic Review. The following defines the words to be abbreviated in one local and the abbreviations in another, where order matters. Note that if more than one word share the same abbreviation and one is a substring of the other, include the longest word first in order.

      Code:
      clear
      input str63 Journal_e float IF1_omega_w1
      "International Economic Review"                                    .238486
      "The Journal of World Economy"                                   .20098802
      "China Rural Survey"                                             .09736695
      "Modern Economic Science"                                       .072677195
      "Researches in Chinese Economic History"                         .04450123
      "Economic Research Journal"                                      .03934519
      "The Journal of Quantitative & Technical Economics"              .03745284
      "Zhejiang Finance"                                               .03477633
      "Tourism Science"                                               .029117016
      "Ancient and Modern Agriculture"                                 .02865064
      "World Economy Studies"                                          .02840467
      "Scientific and Technological Management of Land and Resources"  .02704981
      "Finance & Trade Economics"                                      .02460474
      "Tourism Tribune"                                               .021358477
      "Economic Theory and Business Management"                       .019578734
      "Journal of Beijing Forestry University"                        .016145939
      "Chinese Rural Economy"                                         .011040545
      "Journal of Shanghai University of Finance and Economics"       .009785404
      "Economic Review"                                               .007974063
      "Value Engineering"                                             .005818428
      end
      
      local fullnames journal economics economic economy international university technology ///
      technological technical theory finance agriculture science scientific engineering quantitative ///
      business management history researches research resources resource
      
      local abbrevs J Econ Econ Econ Int Uni Tech Tech Tech Theo Fin Agr Sci Sci Eng Quant Bus ///
      Mgmt Hist Res Res Resou Resou
      
      g journal= Journal_e
      local i 1
      foreach w of local fullnames{
          replace journal = proper(subinstr(lower(journal), "`w'", word("`abbrevs'", `i'), .))
          local ++i
      }
      
      replace journal=ustrregexra(journal, "\bAnd\b|\bOf\b|\bThe\b|\bIn\b", "",.)
      set scheme s1mono
      gr hbar IF1_omega_w1, over(journal, sort(1)) bar(1, fcolor(none) lcolor(black)) ytitle("")
      Click image for larger version

Name:	Graph.png
Views:	1
Size:	36.3 KB
ID:	1675862

      Last edited by Andrew Musau; 30 Jul 2022, 21:21.

      Comment


      • #4
        Dear Andrew, Thanks a lot for this helpful suggestion. We are almost there. How can I re-order the graph so that the journal with larger weight is on the top (rather than on the bottom now)? Thanks.
        Ho-Chuan (River) Huang
        Stata 19.0, MP(4)

        Comment


        • #5
          I got it.
          Code:
          gr hbar IF1_omega_w1, over(journal, sort(1) reverse) bar(1, fcolor(none) lcolor(black)) ytitle("")
          Ho-Chuan (River) Huang
          Stata 19.0, MP(4)

          Comment

          Working...
          X