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: Running Product Function


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: Running Product Function
Date   Sun, 9 Dec 2012 21:56:13 +0000

That is reasonable if and only if zero is in effect a code for missing
in your situation.

(In terms of your earlier reference, -prod()- is a user-written -egen-
function which must be installed from

STB-51  dm71  . . . . . . . . . . . .  Calculating the product of observations
        (help prod if installed)  . . . . . . . . . . . . . . . . . .  P. Ryan
        9/99    pp.3--4; STB Reprints Vol 9, pp.45--48
        extension to egen for producing the product of observations

Please remember to explain _where_ you obtained user-written code.)

Nick

On Sun, Dec 9, 2012 at 9:40 PM, Yuval Arbel <[email protected]> wrote:
> I don't have negative values, but I have zeros, in which case I can
> replace them by one and then take the -ln()-
>
> On Sun, Dec 9, 2012 at 11:31 PM, Nick Cox <[email protected]> wrote:
>> Oddly enough I was thinking earlier today about how you would
>> generalise this if any values were not positive.
>>
>> If any value is zero, then the product becomes zero; otherwise one
>> would need to separate out products of -abs()- and -sign()-.
>>
>> Nick
>>
>> On Sun, Dec 9, 2012 at 9:19 PM, Yuval Arbel <[email protected]> wrote:
>>
>>> Please ignore my previous e-mails regarding this question
>>>
>>> After a short additional search, I found a very nice (and well known)
>>> trick proposed by Nick Cox to address the problem (which, from some
>>> reason did not come to my mind):
>>>
>>> bysort group : gen prod = sum(ln(x))
>>> by group : replace prod = exp(prod[_N])
>>>
>>> On Sun, Dec 9, 2012 at 11:05 PM, Yuval Arbel <[email protected]> wrote:
>>>> P.S. According to stata's help, the details of the author of the
>>>> -prod()- function is:
>>>>
>>>> Philip Ryan
>>>> Department of Public Health
>>>> University of Adelaide
>>>> South Australia
>>>> [email protected]
>>
>>
>> On Sun, Dec 9, 2012 at 10:53 PM, Yuval Arbel <[email protected]> wrote:
>>
>>>>> I appreciate very much your assistance in the following question:,
>>>>>
>>>>> I'm looking for an equivalent function for -gen y1=sum()- which will
>>>>> calculate running product for each point in time
>>>>>
>>>>> In fact, what I would like to calculate is a running geometric mean
>>>>>
>>>>> Note also that -gen y2=prod()- does not work (i.e., stata does not
>>>>> identify the function). Only -egen y2=prod()- works, but it generates
>>>>> only one product for each panel, and this is not what I need.
>>>>>
>>>>> Finally, I tried the -amean- command,, but it simply gives summary
>>>>> statistics of different means, and it is not a function..
*
*   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