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

Saved results, more details

mycmd6.ado:
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
    }
end

program define mycmdsub
    version 6.0
    args name touse detail
    summarize `name' if `touse', `detail'
end
After mycmd6 mpg weight length:
        . return list
        
        scalars:
               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