Announcement

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

  • Why the option sort() allow accepting non-existing variable in graph bar?

    Dear Stata users,

    I ran into a problem today that has been bothering me. I was making a bar chart, and when I was writing the sort() suboption inside the over() option, I accidentally misspelled a variable name. As you can imagine, I didn't get the sorted bar chart I wanted. But what's worth noting is that Stata still produced a bar chart every time — it just wasn't sorted. So I kept adjusting things over and over, but I still couldn't get the correct bar chart. In the end, I discovered that I had misspelled the variable name, and that variable didn't even exist in the dataset. So naturally, sort didn't produce the ordering I wanted. But here's the question: this was a variable that doesn't exist at all — why didn't Stata throw an error? Why did it just ignore the problem and output the graph as if nothing had happened?

    Code:
    sysuse educ99gdp, clear
    generate total = private + public
    graph hbar (asis) public private, over(country, sort(total) descending) stack name(g1, replace)
    graph hbar (asis) public private, over(country, sort(toal) descending) stack name(g2, replace)
    graph combine g1 g2
    Code:
    sort(varname)                put bars in prespecified order
    sort(#)                      put bars in height order
    sort((stat) varname)         put bars in derived order
    Click image for larger version

Name:	why.png
Views:	1
Size:	166.3 KB
ID:	1787488

  • #2
    We will look into it and maybe either add a warning message or error out in this case in a future update.

    Comment


    • #3
      Thank you, Hua Peng (StataCorp) .

      Comment

      Working...
      X