# Density Estimation

Parametric density functions of ratios of normal distributions based on the results demonstrated by Geary (1930, J of the Royal Statistical Society) and Marsaglia (1965, J of the American Statistical Association). Special coding features include the simulation of normal variables, the use of a forvalues loop to generate a series of ratios of normal variables, the use of SMCL in a caption, and the incrementation of a local counter for manipulating the intensity of color red.

## Code

```#delimit ;
set more off ;
clear all ;
set memory 200m ;

drawnorm y1-y2, n(500000) clear seed(54321) ;
generate c1 = y1/y2 ;

local n 0 ;
forvalues v = 10(-2)2 { ;
generate r`++n' = (6*1/3+y1)/(`v'*1/8+y2) ;
} ;

local n 0 ;
local opt "lwidth(*1.2) recast(line)" ;

twoway (hist c1 if inrange(c1,-5,5), `opt' lcolor(red))
(hist r2 if inrange(r2,-5,5), `opt' lcolor(red*.`++n'))
(hist r3 if inrange(r3,-5,5), `opt' lcolor(red*.`++n'))
(hist r4 if inrange(r4,-5,5), `opt' lcolor(red*.`++n'))
(hist r5 if inrange(r5,-5,5), `opt' lcolor(red*.`++n'))
(hist r6 if inrange(r6,-5,5), `opt' lcolor(red*.`++n'))
, xtitle("") ylabel(none)
legend(position(11) size(*.8) ring(0) cols(1) symxsize(*.2)
label(1 "Cauchy: N(0,1) / N(0,1)")
label(2 "(6/3 + N(0,1)) / (10/8 + N(0,1))")
label(3 "(6/3 + N(0,1)) / (8/8 + N(0,1))")
label(4 "(6/3 + N(0,1)) / (6/8 + N(0,1))")
label(5 "(6/3 + N(0,1)) / (4/8 + N(0,1))")
label(6 "(6/3 + N(0,1)) / (2/8 + N(0,1))"))
title("Ratios of normal distributions", margin(medlarge) size(*.8))
caption("{bf:Geary (1930)}: The ratio of two N(0,1) is a Cauchy"
"{bf:Marsaglia (1965)}: The ratio of two c+N(0,1) is a Non-normal", size(*.8))
saving(ratios_normals.gph, replace);

graph export ratios_normals.pdf, replace ;```