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

st: Re: becoming loopy


From   baum <baum@bc.edu>
To   statalist@hsphsun2.harvard.edu
Subject   st: Re: becoming loopy
Date   Tue, 23 Jul 2002 08:42:56 -0400

--On Tuesday, July 23, 2002 2:33 -0400  Elisabeth wrote:

I have to create the following 19 new variables:		newvars=(me_
* var1)+(ppg_ * var1) for each observation in the data set (510)
Is there a way for me to do this in one step. If not, can you please tell
me how?
* replace the postfixes with values specific to your dataset
local after aa bb cc dd ee ff gg hh ii jj kk ll mm nn oo pp qq rr ss
foreach e of local after {
gen new_`e' = (me_`e' * var1) + (ppg_`e' * var1)
}

which will give you new_aa, new_bb, ... Note well the use of backtick (`) rather than apostrophe (') on the LHS of each macro.

Nick Cox' Stata Journal Speaking Stata column 'How to face lists with for..titude' is very useful here.

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