Announcement

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

  • Displaying values not in the data - barchart

    Hi all,

    I have a dataset containing a variety of firms operating in some countries and year. The dataset looks approximately like this:
    FIRM ID COUNTRY YEAR
    Firm 1 AT 2001
    Firm 2 BE 2003
    Firm 3 BE 2002
    Firm 1 AT 2002

    What I'm trying to do is to to create a bar chart for each year showing the number of firms (y axis) and the country they belong to (x axis). The issue I have is that when I take the subset for each year, some countries disappear as I don't have observations within that year, therefore the bar chart would display only countries for which I have observations in that year. For example, in the table above, when plotting for 2001, the bar chart would exclude BE as there are no observations for BE in 2001, What i would like to do is to include BE and show it has 0 observations
    How could I solve this issue?

    Thanks in advance for your help.

  • #2
    Your data example gives the flavour but not the magnitude of your problem. How many countries? How many years? If you create a portfolio of such graphs, how is any reader (including yourself) going to look through and easily and effectively absorb patterns?

    Here is your data example again with code for various examples. I use catplot from SSC -- which is just a wrapper for graph bar, graph hbar or graph dot, either of which could be used directly -- and tabplot from the Stata Journal.

    In short, don't do that then! http://catb.org/jargon/html/D/Don-t-do-that-then-.html

    Or, less flippantly, use a by() or over() option or any equivalent design that shows holes in the data where they (don't) exist.

    If some variation on these approaches doesn't seem to work well enough. we need more information on the size of the real problem.


    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str6 firmid str2 country int year
    "Firm 1" "AT" 2001
    "Firm 2" "BE" 2003
    "Firm 3" "BE" 2002
    "Firm 1" "AT" 2002
    end
    
    set scheme s1color 
    
    catplot country year, recast(bar) name(Z1)
    
    catplot country, by(year) recast(bar) name(Z2)
    
    tabplot country year, showval name(Z3)
    Click image for larger version

Name:	Z1.png
Views:	1
Size:	14.3 KB
ID:	1694664
    Click image for larger version

Name:	Z2.png
Views:	1
Size:	16.1 KB
ID:	1694665
    Click image for larger version

Name:	Z3.png
Views:	1
Size:	13.7 KB
ID:	1694666

    Comment


    • #3
      Hi Nick,

      Thanks for the reply,

      More specifically, I have observations in 21 countries over 8 years (around 5000 obs.). Some of these countries have 0 observations in some years. I would like to have a separate bar chart for each year, and also showing countries with 0 observations when it is the case.

      Comment


      • #4
        My design should work reasonably well for a problem of that size. Wanting a separate chart for each year strikes me as perverse -- I am playing a potential examiner, reviewer, reader of your work -- and it's a personal rule that I don't suggest code for what I think is a bad idea. Sorry if that seems disappointing.

        Comment

        Working...
        X