Thanks Nick, I now rest my case. To wrap up this thread
***My problem
automating (after regress)
test avgspring = deltaspring
test avgcrsgpa = deltacrsgpa, accum
.
.
.
test avgfrstsem = deltafrstsem, accum
**Ernests Solution (if spring, crsgpa and all other suffixes are in the
varlist)
local i=0
foreach origvars of varlist spring crsgpa frstsem {
if `i'==0 test avg`origvars' = delta`origvars'
else test avg`origvars' = delta`origvars' , accum
local i = `i' + 1
}
** Nicks solution (if not in varlist)
foreach origvars in spring crsgpa frstsem {
We can also extract suffixes from a varlist with the same stub.
foreach v of var avg* {
local V : subinstr local v "avg" ""
local suff "`suff'`V' "
}
Now build up the tests:
local i = 0
foreach s of local suff {
if `i++' == 0 test avg`s' = delta`s'
else test avg`s' = delta`s', accum
}
Note how the incrementation of local macro i is performed in place (stata8)
Ronnie
*
* 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/