>> Home >> Resources & support >> Users Group meetings >> 5th UK meeting

Saved results, more details

program define mycmd6, rclass
    version 6.0
    syntax [varlist] [if] [in] [, Detail]

    marksample touse

    tokenize `varlist'

    return scalar nvar = 0
    while "`1'" != "" {
        mycmdsub `1' `touse' `detail' 
        macro shift
        return scalar nvar = return(nvar) + 1

program define mycmdsub
    version 6.0
    args name touse detail
    summarize `name' if `touse', `detail'
After mycmd6 mpg weight length:
        . return list
               r(nvar)        =  3
Note use of return(nvar) rather than r(nvar). return() is used to consume results you have set in the program. r() is used to consume results of other commands.
The Stata Blog: Not Elsewhere Classified Find us on Facebook Follow us on Twitter LinkedIn Google+ Watch us on YouTube