»  Home »  Resources & support »  Users Group meetings »  1999 UK Stata Users Group meeting »  Low-level parsing, revisited

Low-level parsing, revisited

  • gettoken allows token-by-token low-level parsing
  • Useful for two-word commands

    • Pull a subcommand off of the original command line
    • Put the rest of the original command line back in `0' for high-level parsing
              . mycmd6 sum mpg weight if foreign
      
              program define mycmd6              /* `0'      : sum mpg weight if foreign */
                  version 6.0
                  gettoken subcmd 0 : 0          /* `subcmd' : sum                       */
                                                 /* `0'      : mpg weight if foreign     */
                  syntax [varlist] [if] [in]     
                  if "`subcmd'" == "sum" {
                      ...
                  }
                  ...
              end
      
      This is similar to the following in Perl:
              ($subcmd,$zero) = split(/ /,$zero,2) ;

Stata

Shop

Support

Company


The Stata Blog: Not Elsewhere Classified Find us on Facebook Follow us on Twitter LinkedIn YouTube Instagram
© Copyright 1996–2022 StataCorp LLC   •   Terms of use   •   Privacy   •   Contact us