Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, is already up and running.

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

Re: st: compounding interest

From   David Kantor <>
Subject   Re: st: compounding interest
Date   Fri, 23 Jul 2010 14:50:49 -0400

At 02:37 PM 7/23/2010, Jurgen Sidgman wrote:

Does any one know how to multiply two or more values located in the same column but in different rows?
For example, in the first column I have the following information:
Row 1: 2
Row 2: 3
Row 3: 4
Row 4: 2

What I want to do is to calculate:
Row 1 x Row 2 = 6
Previous result x Row 3 = 24
Previous result x Row 4 = 48

Assuming the values are in a variable named x, ...
gen y = x if _n==1
replace y = y * x[_n-1] if n>1

This can also be done under a -by- construct.

*   For searches and help try:

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