On Sun, 7 Apr 2013, Riccardo (Jack) Lucchetti wrote: > On Sat, 6 Apr 2013, Giuseppe Vittucci wrote: > >> Dear all, >> >> I would like to plot the kernel density estimates of a particular >> variable across two different years in the same graph. >> >> Is there a way to do it in gretl? > > One of the possible solutions is to use the kdensity() function con construct > a matrix which is then handed to gnuplot.
Actually, it may be convenient to slightly generalise this and wrap it into a function. See below: <hansl> set echo off set messages off function void double_density(series x, series d) string s = argname(d) matrix d0 = kdensity(d ? NA : x) matrix d1 = kdensity(d ? x : NA) matrix dd = (d0 ~ NA) | (d1[,1] ~ NA ~ d1[,2]) sprintf cn "x %s=0 %s=1", s, s colnames(dd, cn) gnuplot 2 3 1 --matrix=dd --with-lines --output=display end function open australia.gdt dum = t<1980:1 double_density(IAU, dum) open mroz87.gdt double_density(WA, LFP) </hansl> ------------------------------------------------------- Riccardo (Jack) Lucchetti Dipartimento di Scienze Economiche e Sociali (DiSES) Università Politecnica delle Marche (formerly known as Università di Ancona) r.lucchetti(a)univpm.it http://www2.econ.univpm.it/servizi/hpp/lucchetti -------------------------------------------------------