# Displaying frequency when using kernel density estimation

I am trying to plot a kernel density of a single variable in Stata where the y-axis is displayed as a frequency rather than the default density scale. For a histogram, this is trivial; the syntax is:

histogram x, frequency


Furthermore, if I wished to plot a histogram with a kdensity overlaid and maintain the frequency scaling, I would type:

histogram x, frequency kdensity area(n)


where n is the number of non-missing observations.

However, I cannot find a command to plot a simple kdensity on a frequency scale. I imagine a workaround could be to draw the histogram with the frequency option and set the colour to white (so it is invisible against the background) and overlay a scaled kdensity, but this seems a little cumbersome.

• Please see advice in the Help Center on software-related questions. – Nick Cox Feb 20 '15 at 9:43
• I'm sorry, I should have checked there first. I will not ask another off-topic code question again. – singlepeaked Feb 20 '15 at 9:47

Nothing stops you using different units, but it is meaningless to ask for frequencies pure and simple. The scale could only be frequency per unit of measurement. How to get that shown depends on the language or environment you are using but in Stata, you would need to do calculations off-stage, multiplying the densities shown as axis labels by the total frequency in the distribution and ensuring that frequencies per unit $=$ total frequency $\times$ probability per unit are the axis labels the reader sees.
Hint: mylabels from SSC is a Stata way to get axis labels shown on a different scale from that used by a plot command.
• Hello Nick, I will be posting a follow up question on Statalist as I am having some problems executing the mylabels command. I hope this is the correct etiquette. – singlepeaked Feb 20 '15 at 11:23