Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Re: running product


From   "Jitian sheu" <jtsheu@bu.edu>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: Re: running product
Date   Fri, 4 Apr 2003 15:09:45 -0500

you may like to try the following:

gen b=.
replace b=1 if _n==1
replace b=a[_n]*b[_n-1]  if n>=2
replace b=. if _n==1


----- Original Message -----
From: "Hugh Gross" <hughgross@attbi.com>
To: <statalist@hsphsun2.harvard.edu>
Sent: Friday, April 04, 2003 2:58 PM
Subject: st: running product


> Is there an easy way in Stata to create a running product similar to the
> ease with which one can create a running sum using the sum command?
>
> In the example below, variable "a" would be the existing data and variable
> "b" would be the desired result.
>
> Data:
>
> a    b
> 1    .
> 2    2
> 3    6
> 4    24
>
> Many thanks.
>
> Hugh Gross
> hughgross@attbi.com
>
> *
> *   For searches and help try:
> *   http://www.stata.com/support/faqs/res/findit.html
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
>

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index