*
* Syntax:
*
* @Histogram( options ) series start end
*
* Computes and displays a density historgram for the series.
*
* Options:
*   DISTRIB=[NONE]/NORMAL. For DISTRIB=NORMAL, shows an overlay of the normal
*    density.
*   STATS/[NOSTATS] Displays series statistics in the margin
*   HLABEL=horizontal axis label [not used]
*   VLABEL=vertical axis label [not used]
*   HEADER=header label [not used]
*   COUNTS/[NOCOUNTS] Computes and displays counts in each bin rather than density
*   MAXGRID=maximum number of bins [25]
*
* Revision Schedule
*  03/03 Written by Estima.
*
procedure Histogram series start end
type series series
type integer start end
*
option choice  distrib 1 none normal
option integer maxgrid 25
option switch  stats
option string  hlabel
option string  vlabel
option string  header
option switch  counts
*
local integer startl endl
local series fx dx nx
local string s
*
inquire(series=series) startl>>start endl>>end
*
stats(noprint) series startl endl
*
clear fx dx nx
density(maxgrid=maxgrid,type=histogram,counts=counts) series startl endl fx dx
spgraph
display(store=s) 'Mean' %mean '\\Std Error' sqrt(%variance) '\\Skewness' %skewness '\\Exc Kurtosis' %kurtosis
if distrib==2 {
   set nx = 1.0/sqrt(%variance)*%density((fx-%mean)/sqrt(%variance))
   scatter(style=bargraph,overlay=line,ovsamescale,header=header,hlabel=hlabel,vlabel=vlabel) 2
   # fx dx
   # fx nx
}
else {
   scatter(style=bargraph,header=header,hlabel=hlabel,vlabel=vlabel) 1
   # fx dx
}
*
if stats
   grtext(position=upright) s
spgraph(done)
end

