Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: st: geometric means


From   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
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.

Nick
[email protected]


On 11 June 2013 12:42, Nick Cox <[email protected]> wrote:
> Check out -egen-.
>
> Nick
>
>
> On 11 Jun 2013, at 10:35, Abu Camara <[email protected]> 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:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index