Announcement

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

  • Kdens and Hist overlay

    Can Stata plot two series with their histograms and kernel densities all in the one chart? something like: twoway (hist x1 || kdensity x1 ) (hist x2 || kdensity x2)

  • #2
    Do you mean something like this?
    Code:
    sysuse auto, clear
    twoway (hist weight || kdensity weight), name(g1)
    twoway (hist price  || kdensity price ), name(g2)
    graph combine g1 g2
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	107.3 KB
ID:	1701258

    Comment


    • #3
      Thanks. Actually no. My idea was to have all on 1 figure rather than 2 (as above)

      Comment


      • #4
        Code:
        sysuse auto, clear
        twoway (hist weight, color(red)) (kdensity weight) (hist price, color(blue)) (kdensity price)
        yields a fairly unappealing result, but maybe it will be a starting point for you.
        Click image for larger version

Name:	Graph.png
Views:	1
Size:	101.8 KB
ID:	1701271

        Comment


        • #5
          Thank you William. Yes, the hidden color overlaps were on my mind too. But this is a point to start experimenting indeed.

          Comment


          • #6
            See how far a histogram and a kernel density estimate compare is a common task, as is comparing histograms and as is comparing kernel density estimates. Comparing two or more histograms and two or more density estimates is another thing.

            See multidensity from SSC for comparison of density estimates.

            https://www.statalist.org/forums/for...lable-from-ssc

            The command name is perhaps not well chosen insofar as it may lead to an expectation that it supports multivariate, or even bivariate, density estimation, but it doesn't.

            Comment

            Working...
            X