Bookmark and Share

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


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

st: How do I create a loop that calculates new variables by performing the simple mathematical function of subtracting one varlist on another varlist?


From   "Saporito, Salvatore J" <[email protected]>
To   "[email protected]" <[email protected]>
Subject   st: How do I create a loop that calculates new variables by performing the simple mathematical function of subtracting one varlist on another varlist?
Date   Mon, 9 Jan 2012 02:47:44 +0000

I am trying to subtract one sequential list of variables (e.g., a1 to a73) from another sequential list (e.g., b1 to b73) using a loop statement such as the "foreach..." I am trying to avoid repeating the same, simple function (in this case 73 times).

Specifically, I want a loop that repeats this:

gen h7a001=h7r001-h7t001
gen h7a002=h7r001-h7t002
to
gen h7a073=h7r003-h7t073

Simple question but I am trying to learn Stata so that I can use the power of its programming capabilities. This particular challenge eludes me.

Thanks, 

Sal

*
*   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/


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