Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, is already up and running.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: geometric means

From   Nick Cox <>
To   "" <>
Subject   Re: st: geometric means
Date   Wed, 12 Jun 2013 08:34:34 +0100

There's an -egen- function -gmean()- in -egenmore- (SSC), but the
problem  yields also to elementary mathematics and official Stata:

sysuse auto
egen gmean = mean(ln(mpg)), by(rep78)
replace gmean = exp(gmean)

Note that you can't take this further and go

egen gmean2 = exp(mean(ln(mpg))), by(rep78)

because -egen- expects to see an -egen- function on the right-hand
size and -exp()- is not an -egen- function. Why then is the first code
OK? Because the -egen- function -mean()- can work on an expression and
a call to a Stata function is fine.

The overloading of the word "function" needs a little care here.
-egen- functions are those documented under -egen-. Stata functions
are documented under -functions-. There is sometimes scope to use
Stata functions _inside_ calls to -egen- functions, as here. -egen-
functions cannot be used outside -egen- in any circumstances.


On 11 June 2013 12:42, Nick Cox <> wrote:
> Check out -egen-.
> Nick
> On 11 Jun 2013, at 10:35, Abu Camara <> wrote:
>> Hi Stata list,
>> I want to compute geometric means by year (time series)  for a list of
>> countries with Stata's "ameans" command.
>> BY and OVER are not supported by ameans.
*   For searches and help try:

© Copyright 1996–2015 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index