[Gretl-users] kurtosis command line

Allin Cottrell cottrell at wfu.edu
Fri Jul 31 22:06:52 EDT 2009


On Thu, 30 Jul 2009, jtr jacob wrote:

> Is there a command line function that can be used in a gretl
> script to evaluate kurtosis and skewness of variables. I am
> looking to use it in an if loop as in :
>
> if kurtosis(Y) > xxx do this

No, there's no built-in function to do this.  This is
functionality that is rarely wanted, and in such cases it makes
more sense to write your own function (unless it is excessively
difficult, which is certainly not the case here).  We don't want
the namespace of built-in gretl functions to be over-extended with
oddities.

function kurtosis (series x)
  scalar n = nobs(x)
  series d = x - mean(x)
  scalar m4 = sum(d^4) / n
  scalar s4 = (sst(x)/n)^2
  # See http://en.wikipedia.org/wiki/Kurtosis
  scalar k = (m4 / s4) - 3.0
  return scalar k
end function

This function could easily be made more compact, at some cost in
readability.  Test case:

open data4-1
summary price
scalar kp = kurtosis(price)

Allin Cottrell


More information about the Gretl-users mailing list