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

RE: st: Multiple tests


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: Multiple tests
Date   Fri, 4 Apr 2003 10:37:49 +0100

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/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index