Nick, thanks. For now, as u point in your subsquent email, the original
variables are in the varlist so the solution provided by Ernest works. Just
one thing
When it comes to the test, you use
foreach s of local suff {
if `i++' == 0 test avg`s' = delta`s'
else test avg`s' = delta`s', accum
}
While Ernest uses
foreach origvars of varlist spring crsgpa frstsem {
if `i'==0 test avg`origvars' = avg`origvars'
else test avg`origvars' = avg`origvars' , accum
local i = `i' + 1
}
(ignoring what is in foreach and focusing on the actual test) You have one
line less (i am guessing it is achieved by if `i++'). Please throw some more
light on this.
Ronnie
-----Original Message-----
From: [email protected]
[mailto:[email protected]]On Behalf Of Nick Cox
Sent: 4. april 2003 11:38
To: [email protected]
Subject: RE: st: Multiple tests
Ernest Berkhout replied to Ronnie Babigumira
>
> >test avgspring = deltaspring
> >test avgcrsgpa = deltacrsgpa, accum
> >test avgfrstsem = deltafrstsem, accum
> >
> >and it is OK for a few variables, however, I need to do
> this for many more
> >variables so my question is, CAN THIS BE AUTOMATED (can i
> repeat myself
> >without running mad).
>
> local i=0
> foreach origvars of varlist spring crsgpa frstsem {
> if `i'==0 test avg`origvars' = avg`origvars'
> else test avg`origvars' = avg`origvars' , accum
> local i = `i' + 1
> }
>
> should do the trick I think.
A few minor variations on this theme follow. First,
fixing the typo:
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
}
Second, this won't work unless
spring crsgpa frstsem
is actually a varlist, and that doesn't seem guaranteed.
foreach origvars in spring crsgpa frstsem {
should work.
Even more automation is possible. Let me assume that
there is an one-to-one matching between the -avg*-
and the -delta*-. How to get the suffixes -spring ...-
etc.?
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.
Nick
[email protected]
*
* 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/
*
* 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/