Announcement

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

  • Stacked charts

    Hi, I am trying to represent my data in a stacked chart. I have data on export and import. What I am trying to show is the percentage of the observations in which i have observations for both export and import, either export or import and no observations at all. To be more precise, I'm trying to visualise it in a similar manner as Helpman et al. (2008) does in their "Estimating Trade Flows: Trading Partners and Trading Volumes", which looks like this
    Click image for larger version

Name:	Skärmklipp.PNG
Views:	1
Size:	21.2 KB
ID:	1492297


    I have created two three variables. TradeBoth is = 1 given that both export and import has a positive value. TradeOne is 1 given that one of export or import has a positive value, but the other one is unobserved. A variable "missing" that is 1 given that both export and import is missing. If these variables are not 1, then I have them as "."


    I tried initially to run something like this to then built upon it. However, I can't get percent to work.

    graph bar (percent) TradeBoth TradeOne missing, over(year) stack title("Data distribution")
    Im trying to do this through year 1996 to 2017.

    Thank you for any helpful answers!

    Sincerely,
    Jonathan

  • #2
    Helpman et al. (2008) "Estimating Trade Flows: Trading Partners and Trading Volumes": please see our advice on references at http://www.statalist.org/forums/help#references

    I can't see that graph as exemplary.

    1. With 28 years, they can't avoid putting year labels on a slant. You have 22, and the problem will bite you too.

    2. Stacking although easy to understand in principle can make it difficult to follow each component quantitatively: typically only the component stacked first is easy to follow. .

    3. A legend is at best a necessary evil requiring reference back and forth from the reader.

    I have an alternative suggestion. You don't give a data example (even though what you want to plot is in essence 22 years with 3 percents for each) -- please see our advice on data examples at http://www.statalist.org/forums/help#stata -- so I made one up with roughly the same number of years.

    See https://www.statalist.org/forums/for...updated-on-ssc for the command used here, noting that if interested the code should be downloaded from the latest link given by

    Code:
    search tabplot, sj
    which at the time of writing is

    Code:
    . search tabplot, sj
    
    Search of official help files, FAQs, Examples, SJs, and STBs
    
    SJ-17-3 gr0066_1  . . . . . . . . . . . . . . . .  Software update for tabplot
            (help tabplot if installed) . . . . . . . . . . . . . . . .  N. J. Cox
            Q3/17   SJ 17(3):779
            added options for reversing axis scales; improved handling of
            axis labels containing quotation marks
    If you do this yourself, gr0066_1 will be a clickable link.

    Code:
    * sandbox
    webuse grunfeld, clear
    gen whatever = cond(invest < 50, 1, cond(invest < 200, 2, 3))
    label def whatever 1 "both directions" 2 "one direction" 3 "no trade"
    label val whatever whatever  
    tab year whatever
    
    * for subtle reasons, specifying format(%tyY) does nothing useful in -tabplot-, so
    * we define value labels for the years which are just the last two digits
    
    forval y = 1935/1954 {
        local Y = substr("`y'", -2, 2)
        label define year `y' "`Y'" , modify
    }
    label val year year
    
    set scheme s1color
    
    tabplot whatever year, percent(year) yreverse showval(format(%1.0f)) ///
    bfcolor(eltgreen*0.2) ytitle("") subtitle(% by year)
    Click image for larger version

Name:	nilsson.png
Views:	1
Size:	31.0 KB
ID:	1492301



    Naturally, display of percents is just an option, but often a useful one.

    In your case, I think you're much better off putting your three indicators together:

    Code:
    gen outcome = cond(TradeBoth == 1, 1, cond(TradeOne == 1, 2, cond(missing == 1, 3, .)))
    label define outcome 1 "both directions" 2 "one direction" 3 "no trade"
    label val outcome outcome

    Comment


    • #3
      Nick Cox you're awesome! many thanks!!

      Sincerely,
      John

      Comment

      Working...
      X