Ronnie Babigumira
>
> 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.
Stata 8 adds, for local macros, the ++ and -- increment
and decrement operators familiar to programmers in C
and similar languages.
In particular
`i++'
means -- in context -- use the current
value `i' here and _then_ increment local macro i
(bump it by by 1), so that any later reference
to `i' will use the incremented value.
`++i' increments the local macro i and then uses it.
`i--' and `--i' are "use then decrement (bump down by 1)" and
"decrement then use".
See [U] 21.3.4 and [U] 21.3.7 or [P] macro.
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/