Virata manual

graph kdensity

A smoothed version of a histogram, drawn as a curve. Better than a histogram when you want to lay two or three groups over each other and compare shapes.

What we have

  • statistics: count, max, mean, median, min, sum
  • over() for the categories and by() for a second split
  • title(), ytitle() and saving()
  • one self-contained .html file: no server, no internet, nothing to install
  • a table view beside the chart, so the numbers can be read off

Coming later

  • saving as PNG or SVG — graph export does not exist yet
  • graph twoway and graph matrix, which are refused
  • 84 more of the 105 catalogue chart types

How you write it

graph kdensity varname [if] [weight], [by(groupvar)] [bwidth(#)]

A smooth density curve (Stata's epanechnikov default). by() draws one curve per group, up to 8.

What your data has to look like

One row per person or record, with these columns (named here as they are in vira.sample01):

ColumnHoldsWhat it does in the chart
sectora categoryoptional: one curve for each value
mpcea numberthe values the curve smooths

Three rows of it would look like this:

Rural  2410.55
Urban  4102.8
Rural  2988.1

The example

. sysuse vira.sample01, clear
. graph kdensity mpce, by(sector)

That is the real file the command wrote — open it on its own. It is one self-contained page with no internet connection needed, so you can email it or drop it into a report.