*
* Creates a Q plot for a series against a hypothesized distribution
*
* Syntax:
*
* @QPlot( options )  series  start end
*
* Parameters:
*
*  series       series to graph
*  start  end   range to graph
*
* Options:
*  DISTRIB=[NORMAL]/EXPONENTIAL
*  SMPL=Dummy series with entries to include [all]
*  TITLE=" descriptive title for graph "
*  MEAN=mean for comparison distribution [sample mean]
*  STDDEV=standard deviation for comparison distribution [sample standard error]
*  BOUND=lower bound for exponential distribution [0]
*
* Revision Schedule:
*  03/07 Written by Tom Doan, Estima
*
procedure qplot series start end
option choice distrib 1 normal exponential
option series smpl
option real   mean
option real   stddev
option real   bound
option string title
*
local series copy testdist
local integer n
local real meanl stddevl boundl
*
sample(smpl=smpl) series start end copy 1
compute n=%nobs
*
order copy 1 n
stats(noprint) copy 1 n
compute meanl  =%if(%defined(mean),mean,%mean)
compute stddevl=%if(%defined(stddev),stddev,sqrt(%variance))
compute boundl =%if(%defined(bound),bound,0.0)
*
if distrib==1
   set testdist 1 n = %invnormal((t-.5)/(n+1))*stddevl+meanl
else
if distrib==2
   set testdist 1 n = boundl+(boundl-meanl)*log(1-(t-.5)/(n+1))

scatter(line=||0.0,1.0||,style=dots,header=title,vlabel="Quantiles",hlabel="Data")
# copy testdist 1 n
end


