Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

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

st: Calculating compound interest using loops?

From   Sara Kimberlin <[email protected]>
To   [email protected]
Subject   st: Calculating compound interest using loops?
Date   Mon, 9 Jul 2012 12:22:39 -0700


I'm trying to calculate annual interest payments on a 30-year loan,
with interest compounding monthly, and can't figure out how to write
the code efficiently.

Pre-defined variables include principal, rate, and monthly_payment.  I
know I can manually calculate the amount of interest for each monthly
period like this:

gen interest_month1 = principal * rate

gen interest_month2 = (principal - (monthly_payment * 1) +
interest_month1) * rate

gen interest_month3 = (principal - (monthly_payment * 2) +
interest_month1 + interest_month2) * rate

gen interest_month4  = (principal - (monthly_payment * 3) +
interest_month1 + interest_month2 + interest_month3) * rate

... and so on through interest_month360.

And then I can manually add up the monthly interest to calculate the
annual interest for each year, e.g.:

gen interest_year1 = interest_month1 + interest_month2... + interest_month12

But I think there must be a way to write this much more efficiently
using loops, and I haven't been able to figure it out.  I'd appreciate
any help.

Thank you,
*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index