Announcement

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

  • generate histograms with descriptive statistics

    Hi,

    I got a question about the histogram command in STATA which I cant solve by googleing it or reading the STATA help article: is it possible to create histograms where there is a box inside the histogram with statistics about the variable of interest like mean, median, st. dev., skewness, and kurtosis and if there is such an option, how would the code look like?

    Thank you very much!

    Cheers,

    Kurt

  • #2
    See help added_text_options.

    Comment


    • #3
      Thank you very much, that helped. But how can I actually run a command in the text option? As far as I read from the STATA help, only text is allowed. Not something like a sum var if ..., options.... But thats what I would need. Am I doing something wrong or is there another syntax for this?

      my code:
      twoway hist monun2 if gdum==0, ///
      frac name(psmonun0a, replace) ///
      plotregion(fcolor(white)) graphregion(fcolor(white)) bcolor(blue*0.7) ///
      text( 1 0.6 {here there should be a command for writing sum statistics into the text box} , place(se) box just(left) margin(l+4 t+1 b+1) width(XX) )

      Thank you!


      Comment


      • #4
        No, you can't embed a command inside the -text()- option. But you can run those commands before you plot the graph, save the relevant statistics as local macros, and then use those in the -text()- option. For example:

        Code:
        summ monun2 if gdum == 0, detail
        local mean = r(mean)
        local median = r(p50)
        local sd = r(sd)
        // etc.
        twoway hist monun2 if gdum==0, ///
        frac name(psmonun0a, replace) ///
        plotregion(fcolor(white)) graphregion(fcolor(white)) bcolor(blue*0.7) ///
        text( 1 0.6 {"mean = `mean', median = `median', sd = `sd'"} , ///
        place(se) box just(left) margin(l+4 t+1 b+1) width(XX) )
        For what it's worth, I think sticking 5 different statistics in a text box on a graph is going to look awfully cluttered, and probably hard to read. Would it be helpful to put them in a -note()- option instead?

        Comment


        • #5
          I embedded an option that does something analogous to this in a new program I've been working on: https://github.com/wbuchanan/eda.

          There is an option in the main program to include reference lines for Tukey's five number summary and it prints mean, sd, and optionally the five number summary as a caption. If that suits your needs you can get all of the histograms you want using eda, but you'll need to turn off the other graphs.

          Comment


          • #6
            Thank you very much that worked out very well!! It doesnt look that awfully, but because I will stack 12 graphs on one a4 page, it gets pretty small...

            But you saved my whole day of STATA work

            Comment


            • #7
              Are you using the graph combine command to put them together on a single page? It has options that deal with scaling the figures which may help the aesthetics of the page overall.

              Comment


              • #8
                No I am doing that in LaTeX afterwards, so I use STATA to generate the graphs, then compile them to eps and then put them into a floatfigure in LaTeX...

                Comment


                • #9
                  You may want to consider gr combine as an option to generate the combined .EPS image. I've built out some info graphics before using it and it might help you if you need to start debugging changes across the two languages.

                  Comment


                  • #10
                    It works fine for me so I wouldnt change it...but I problems will accour I will come back to your solution thanks!

                    Comment

                    Working...
                    X