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

st: Re: running product


From   "Jitian sheu" <[email protected]>
To   <[email protected]>
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" <[email protected]>
To: <[email protected]>
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
> [email protected]
>
> *
> *   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index