Announcement

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

  • Problem in creating Bar Chart with Standard Errors

    Dear Stata Listers,

    I hope you are doing well.

    I have a district-year (bench is district and yeardecision is year) panel data set and I want to construct a bar chart with average before and after a reform in 2010.

    My plan is to construct mean and standard error and then use the following code to construct the bar graph with standard errors:

    Code:
    graph twoway (bar PreRefStateWinsMean PostRefStateWinsMean ) (rcap SEPreRefStateWinsMean SEPostRefStateWinsMean)
    My original data set looks like this:

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str5 bench int yeardecision float(StateWins caselag) byte Reform_Exposure float public_services
    "phc"   2009 .5714286     .5625 0          .
    "quehc" 2009      .52 2.7142856 0 .071428575
    "rwphc" 2009       .5         2 0          .
    "sukhc" 2009    .6875  .5032258 0          .
    ""      2010        .         1 .          .
    "abohc" 2010 .6666667  .3333333 0          .
    "banhc" 2010       .4         2 0          .
    end

    I run the following code, where I first make the average of pre and post reform State Wins (my variable of interest) but I am having problem constructing standard errors. The code up till this point works:

    Code:
    ***Creating Variables to Construct Bar Chart
    generate sdStateWins = .
    replace sdStateWins = StateWins
    
    collapse (mean) StateWins (sd) sdStateWins  (mean) caselag (mean) public_services (mean) public_official (mean) provincial_govt (mean) dist_govt (mean) fed_govt (mean) govresp (mean) firmvsstate , by(bench yeardecision)
    
    summarize StateWins if yeardecision < 2010
    generate PreRefStateWinsMean = r(mean)
    
    summarize StateWins if yeardecision >= 2010
    generate PostRefStateWinsMean = r(mean)
    set more off
    list PreRefStateWinsMean PostRefStateWinsMean //works till here
    graph bar PreRefStateWinsMean PostRefStateWinsMean
    However, when I try to construct the standard errors using following code, I get all missing values for my PreRefStateWinsSE and PostPostRefStateWinsSE variables :
    Code:
    generate PreRefStateWinsSE = PreRefStateWinsMean + invttail(92,0.025)*(sdStateWins / sqrt(93)) //92 are df
    generate PostRefStateWinsSE = PostRefStateWinsMean + invttail(100,0.025)*(sdStateWins / sqrt(101)) //100 are df
    How may I proceed to get a bar chart with standard errors of pre and post reform years with my dataset? Any help in this regard will be really appreciated. Thanks.

    Cheers,
    Roger
    Last edited by Roger More; 14 Aug 2017, 06:31.

  • #2
    Dear all,

    Perhaps anyone can help with one problem since probably the above post is too long and tedious to read.

    How to generate confidence intervals for mean so I can use

    Code:
     graph twoway (bar PreRefStateWinsMean PostRefStateWinsMean ) (rcap SEPreRefStateWinsMean SEPostRefStateWinsMean)
    I have tried the following but I get all missing values for the PreRefStateWinsSE variable :
    Code:
    generate PreRefStateWinsSE = PreRefStateWinsMean + invttail(92,0.025)*(sdStateWins / sqrt(93)) //92 are df
    Thank you very much in advance.

    Cheers!

    Comment


    • #3
      Your code ( in #1 ) included variables not presented in the dataset, hence we cannot provide a specific solution.

      On account of that, in spite of the goodwill (and time, and effort) to approach your problem, unfortunately, I realized I cannot succeed, for there is much information missing.

      Actually, I gather this was the reason for the lack of a useful reply to this thread so far.

      That said, you may reap the correct command by reading this text and fiddling with the examples.
      Best regards,

      Marcos

      Comment


      • #4
        ok, thank you for trying. The link is indeed helpful.

        Comment


        • #5
          I have to dissent partially here. The link given by Marcos in #3 gives advice on how to get a poor graph in a roundabout way.

          https://www.statalist.org/forums/for...way-bar-graphs gives some reactions to precisely the same document.

          The kind of bar chart you're asking for (some names include detonator plot, dynamite plot, plunger plot) is widely used and widely deprecated. A Google search on e.g. plunger plots gives links to several discussions.

          Furthermore, repeating here points from my earlier post:

          1. There is no advantage (beyond pedagogy) to do-it-yourself confidence intervals when ci will do it for you.

          2. statsby is your friend. search statsby to find material, including something I wrote.

          3. There is no attraction to bars starting at zero. We want clear comparisons of estimates and confidence intervals with each other, not with zero!

          4. A legend is at best a necessary evil obliging mental back and forth. Lose the legend (kill the key) if you can.

          5. Fruit salad colours that are gratuitous as well as meaningless?

          I agree with Marcos that if you gave a data example in a reproducible way, it would be easier to provide you with specific code. Meanwhile the link here gives specific and reproducible code.

          Comment


          • #6
            Thanks for clarifying this point anew, Nick.

            I remember to have read the previous message before and I think the arguments are very very strong.

            Convincing enough.

            That said, at least in some branches (here, researchers from the experimental field), I fear dynamite plots are part and parcel of every paper they get published in high-impact-factor journals. I mean, they clearly demand and they push the envelope so as to get these plots, otherwise... Well, by serendipity, I'm about to try to start a partnership with dye-hard fond-of-dynamite-plot fellows. Hopefully I will be able to change their minds.



            Best regards,

            Marcos

            Comment

            Working...
            X