Announcement

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

  • Bar Chart

    Hello everyone, I would like to create a bar chart including 18 variables, each of them including only one value. They are called x1, x2, x3, x4....
    I want the bars of 3 variables to be next to each other and to have a common group heading. So it should basically look like the bar chart that I uploaded here but with 6 groups instead.
    x1 x2 x3 in one group, then x4 x5 x6 and so on
    Unfortunately, I have no clue how to do that. Could anyone help me out please?

    Thank you so much in advance!!








    Click image for larger version

Name:	bdiagr1.jpeg
Views:	1
Size:	21.7 KB
ID:	1675784


    Last edited by Joy Allen; 30 Jul 2022, 04:06.

  • #2
    I think I need a data example to answer this better than I can do at the moment. Please see https://www.statalist.org/forums/help#stata

    I have too many puzzles on exactly what you want.

    Here is some technique.


    Code:
    clear 
    
    set obs 1 
    
    forval j = 1/18 { 
        gen x`j' = `j' 
    }
    
    * start here 
    
    gen id = 1 
    reshape long x, i(id) j(which)
    
    gen group = ceil(_n/3)
    
    bysort group (which) : gen criterion = _n 
    
    separate x, by(criterion) veryshortlabel 
    
    set scheme s1color 
    
    graph bar (asis) x?, over(criterion)  by(group, row(1) note("") legend(off)) nofill
    Click image for larger version

Name:	whateverwhatever.png
Views:	1
Size:	25.5 KB
ID:	1675786

    Comment


    • #3
      Thank you very much! So this is what the variables look like.

      I would like to have a bar chart that depicts the value of these variables. And as I have said, I always want three of them in one group.





      x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 x16 x17 x18
      .3010361 .2753523 .312896 .3325881 .2516735 .3727746 .1792885 .1580234 .1890873 .141951 .144826 .1406338 .1581859 .2043421 .1363363 .1265911 .1610973 .110453
      .3010361 .2753523 .312896 .3325881 .2516735 .3727746 .1792885 .1580234 .1890873 .141951 .144826 .1406338 .1581859 .2043421 .1363363 .1265911 .1610973 .110453
      .3010361 .2753523 .312896 .3325881 .2516735 .3727746 .1792885 .1580234 .1890873 .141951 .144826 .1406338 .1581859 .2043421 .1363363 .1265911 .1610973 .110453
      .3010361 .2753523 .312896 .3325881 .2516735 .3727746 .1792885 .1580234 .1890873 .141951 .144826 .1406338 .1581859 .2043421 .1363363 .1265911 .1610973 .110453
      .3010361 .2753523 .312896 .3325881 .2516735 .3727746 .1792885 .1580234 .1890873 .141951 .144826 .1406338 .1581859 .2043421 .1363363 .1265911 .1610973 .110453

      Comment


      • #4
        Thanks for the data example. The implication is that you should wrap the code in #2 within


        Code:
        preserve 
        keep in 1 
        
        
        restore
        as observations after the first don't differ.

        Sorry, but I don't see anything in #3 that helps me better understand the graph you want. Don't the x1 x2 x3 ... have meanings beyond their names?

        "In mathematics context obscures structure.... In data analysis, context provides meaning." (George W. Cobb)

        Comment

        Working...
        X