st: Calculating compound interest using loops?

Hello,
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,
Sara
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/