The following command can be used to generate a command which consists of several new variables which are generated within a loop.
This could either be done by (e.g. generating a number of log variables)
gen newvar1 = log(var1)
gen newvar2 = log(var2)
etc.
reg depvar newvar1 newvar2
If there are more variables to generate, it can be more handy to use the following commands
local command = ""
local loc = "var1 var2" /* this local contains all original variables */
foreach var of local loc {
gen new`var' = log(`var')
local command = " `command' new`var' "
}
di "`command'"
The new local-macro command
now contains all new variables
newvar1 newvar2
and can be used in any commands.
Leave a Reply
You must be logged in to post a comment.