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

st: RE: running product


From   "Nick Winter" <nwinter@policystudies.com>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: running product
Date   Thu, 27 Mar 2003 13:43:23 -0500

Assuming your original variable is x:

	. generate runprod = x in 1
	. replace runprod = runprod[_n-1]*x in 2/l

The generate statement puts the first value in the first observation of runprod.

Then the replace takes advantage of the fact that replace works its way through the data from beginning to end, and for each observation starting with the second, takes the prior running product, multiplies by the current x, and puts the result in the current running product.

(Note that the final character in the "in 2/l" in the replace statement is the letter "el", for last, not the number one.

Cheers,
Nick Winter


-----------------------------------------------------------
 Nicholas Winter, Ph.D.                     P 202.939.5343
 Policy Studies Associates                  F 202.939.5732
 1718 Connecticut Avenue, NW     nwinter@policystudies.com
 Washington, DC 20009-1148           www.policystudies.com
----------------------------------------------------------- 

> -----Original Message-----
> From: Alessandra Franzosi [mailto:Alessandra.Franzosi@borsaitalia.it] 
> Sent: Thursday, March 27, 2003 1:09 PM
> To: statalist@hsphsun2.harvard.edu
> Subject: st: running product
> 
> 
> How is it possible to generate in Stata a new variable that 
> is the running product of another one?
> 
> Thanks a lot
> 
> Alessandra
> 
> --------------------------------------------------------------
> --------------
> L'utilizzo non  autorizzato  del  presente  messaggio  Ŕ  
> vietato  e  potrebbe costituire  reato. Se il presente
> messaggio non e' a Lei indirizzato, Le saremmo grati  se,  
> via  e-mail,  ne  comunicasse  l'errata  ricezione. Il
> contenuto del presente  messaggio  non deve essere 
> considerato come trasmesso o autorizzato da Borsa Italiana. Borsa
> Italiana non si assume alcuna responsabilitÓ per eventuali 
> intercettazioni, modifiche o danneggiamenti del presente
> messaggio e-mail.
> 
> The unauthorized use of this e-mail is prohibited and could 
> constitute an offence. Please notify Borsa Italiana
> immediately by reply e-mail if you are not the intended 
> recepient. The contents of this message shall be understood as
> neither given nor endorsed by Borsa Italiana. Borsa Italiana 
> does not accept liability for corruption, interception or
> amendment, if any, or the consequences thereof.
> --------------------------------------------------------------
> --------------
> 
> 
> 
> *
> *   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