Stata 15 help for mf__parse_colon


[M-5] _parse_colon() -- Parse utility for Stata prefix commands


mata: _parse_colon("hascolon", "rhscmd")

Inputs (from Stata):

`0' string to be parsed

Outputs (to Stata):

`hascolon' 0 or 1, whether `0' had colon `0' original `0' prior to colon (unchanged if no colon) `rhscmd' original `0' to the right of the colon ("" if no colon)

(Syntax is shown in Stata format because _parse_colon() is intended for use from Stata ado-files. Arguments are names of local macros to be created. Mata function _parse_colon() is in fact void, and each argument is string scalar.)


_parse_colon("hascolon", "rhscmd") is a function designed for use from Stata ado-files to assist in the parsing of prefix commands.


Assume `0' contains "by group: generate x = _n". Then after running mata: _parse_colon(colon, rhs), `colon' contains 1, `0' contains "by group", and `rhs' contains "generate x = _n".


All arguments are string scalar and contain the name of Stata local macros to be created or replaced.


`0' is always split on the left-most colon, so _parse_colon() may be used to process nested colon commands.

Colons inside quotes, parentheses, brackets, or braces are ignored.

mata: _parse_colon("hascolon", "rhscmd") does not abort with error and produces no error messages. If local macro `0' does not contain a colon, then `hascolon' is set to 0 and `rhscmd' is set to "". If a colon is present but nothing appears to the right of it, `hascolon' is set to 1 and `rhscmd' is set to "".

Source code


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