Announcement

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

  • Graph Bar problem with allcategories and nofill option

    Dear User,

    since I can't post a .dta file, I try to explain my problem. I can't create an example dataset since that's the reason I ask my question, because I can't figure out why Stata reacts the way it reacts with my data.

    My dataset consists of 3 variables: age group, categories (which has 12 categories cat1 to cat12, coded by the numbers 180 to 200) and a string variable for departments, called dep. The dep variable looks like this "#B#Y#aa#aa#aa#aa#aa#aa#" and is coded that way for some reasons.

    Since I want to keep all categories shown in the graph (because of the same color), I used 2 options for my stacked bar chart: allcategories and nofill. This is the first graph I create:

    Code:
    global options = "stack asyvars percent allcategories nofill"
    graph bar if categories < 190 & strmatch(dep,"*A*"), over(categories) over(agegrp5) $options
    I uploaded the graph as "correct1.png". So everything is fine with the graph. Not I try to create the next graph:

    Code:
    graph bar if categories < 190 & strmatch(dep,"*A*"), over(categories) over(agegrp5) $options
    This graph is "wrong1a.png" in the attachments. There is an empty space on the right side of the graph wich I expected not to be there. I used a tabulate command
    Code:
    tab agegrp5 categories if categories < 190 & strmatch(dep,"*A*"), miss
    to have a look at missings, but there are none.

    Now I tried the following:
    Code:
    keep if strmatch(dep,"*A*") == 1
    drop if strmatch(dep,"*A*") & agegrp5 == 1
    graph bar if categories<190 & strmatch(dep,"*A*"), over(categories) over(agegrp5) $options
    As you can see in "wrong1b.png", now the graph is looking correct. Using the same tabulte command as above, the table looks the same, no missings and nothing that tells me why there is an empy space on the right of "wrong1a.png". So the strange thing is, when using

    Code:
    drop if strmatch(dep,"*A*") & agegrp5 == 2
    graph bar if categories < 190 & strmatch(dep,"*A*"), over(categories) over(agegrp5) $options
    The graph looks like "correct2.png" with no empty space. So I was trying to figure out the difference between my data between my 2 filters:
    Code:
    if strmatch(dep,"*A*") & agegrp5 == 1
    if strmatch(dep,"*A*") & agegrp5 == 2
    which seems to be the reason of the empty space, but there is no difference in the data I can see. So that's why I think allcategories and nofill must handle the data somehow different.

    Hopy you can help me.

    -Nick
    Attached Files

  • #2
    Sorry, but I got lost here early on. Your first and second graph bar command look identical to me (correct me if I am wrong), so I am mystified at why they produce different results.

    I would get in touch with StataCorp technical support -- because you can send them .dta files. Otherwise we can't reproduce your problem. (I don't understand your reason for not posting example data.)

    Not the question, but my strong prejudice is that stacked bar charts work poorly in most cases. The legend takes up much of the space and tracking each category can be tricky as well as tedious. Search this forum for mentions of tabplot (Stata Journal) f you are interested in alternatives.

    Comment


    • #3
      Dear Nick,

      1) your are right, I was missing a code line with my second graph command:
      HTML Code:
      drop if strmatch(dep,"*A*") & agegrp5 == 1
      So when dropping data, the error occurs.
      2) I can't create an example dataset since using example datasets from Stata (auto or any other), the problem does not occur. So it occurs with my dataset.

      -Nick

      Comment


      • #4

        1) That explains why I couldn't understand that bit. Thanks!

        2) Not my point. It would be sufficient to see a subset of your dataset that allows people to reproduce the problem.

        I've occasionally found that you have to leave out parts of the dataset in a preserve drop graph restore cycle. I don't understand that either.

        Comment


        • #5
          Hi Nick,

          I used preserve-restore, but didn't show that in the code in my first entry. So the reason why I can't subset is, that every time i try to make a small subset, the error does not occur. Since I don't know the nature of the error, it's not possible to subset. Sorry I can provide you with more information, for me, too, it's quite a puzzle why it doesn't work.

          Comment


          • #6
            If you tried tabplot, then I am supposed to know how that works.

            Comment


            • #7
              Here are the tabplots, I used the titles to show the match to the graph bars. Even if tabplots seems to work, I have to use graph bar and I can't switch to another command.
              Attached Files

              Comment


              • #8
                I have to use graph bar
                Where do these rules come from? Sounds intolerable to me.

                Comment


                • #9
                  Actually, I don't have a choice. So do you see anything why graph bar is not working the way I expect it?

                  Comment


                  • #10
                    I can't add to the little I have said before. (Is someone insisting on scheme s2color too? Feel free to ignore the question if I am treading on difficult ground.)

                    Comment

                    Working...
                    X