Stata 15 help for mf_strtoname

[M-5] strtoname() -- Convert a string to a Stata 13 compatible name


string matrix strtoname(string matrix s, real scalar p)

string matrix strtoname(string matrix s)


strtoname(s, p) returns s translated into a Stata name. Each character in s that is not allowed in a Stata name is converted to an underscore character, _. If the first character in s is a numeric character and p is not 0, then the result is prefixed with an underscore. The result is truncated to 32 bytes.

strtoname(s) is equivalent to strtoname(s, 1).

When arguments are not scalar, strtoname() returns element-by-element results.


strtoname() handles strings with only ASCII characters. Use ustrtoname() to produce Stata names with Unicode characters.

strtoname("StataName") returns "StataName".

strtoname("not a Stata name") returns "not_a_Stata_name".

strtoname("0 is off") returns "_0_is_off".

strtoname("0 is off", 0) returns "0_is_off".


strtoname(s, p): s: r x c p: 1 x 1 result: r x c

strtoname(s): s: r x c result: r x c



Source code

Function is built in.

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