📄 mf_st_macroexpand.hlp
字号:
{smcl}
{* 07may2005}{...}
{cmd:help mata st_macroexpand()}
{hline}
{* index st_macroexpand()}{...}
{* index _st_macroexpand()}{...}
{title:Title}
{p 4 4 2}
{bf:[M-5] st_macroexpand() -- Expand Stata macros in string}
{title:Syntax}
{p 8 12 2}
{it:string scalar}
{cmd:st_macroexpand(}{it:string scalar s}{cmd:)}
{p 8 12 2}
{it:real scalar}{bind: }
{cmd:_st_macroexpand(}{it:S}{cmd:,}
{it:string scalar s}{cmd:)}
{p 4 11 2}
Note:
The type of {it:S} does not matter; it is replaced and becomes a
string scalar.
{title:Description}
{p 4 4 2}
{cmd:st_macroexpand(}{it:s}{cmd:)}
returns {it:s} with any quoted or dollar-sign prefixed macros expanded.
{p 4 4 2}
{cmd:_st_macroexpand(}{it:S}{cmd:,} {it:s}{cmd:)}
places in {it:S} the contents of {it:s} with any quoted or dollar-sign
prefixed macros expanded, and returns a Stata return code (it returns
0 if all went well).
{title:Remarks}
{p 4 4 2}
Be careful coding string literals containing quoted or prefixed macros
because macros are also expanded at compile time. For instance,
consider
{cmd:s = st_macroexpand("regress `varlist'")}
{p 4 4 2}
{cmd:`varlist'} will be substituted with its value at compile time. What you
probably want is
{cmd:s = st_macroexpand("regress " + "`" + "varlist" + "'")}
{title:Conformability}
{cmd:st_macroexpand(}{it:s}{cmd:)}:
{it:s}: 1 {it:x} 1
{it:result}: 1 {it:x} 1
{cmd:_st_macroexpand(}{it:S}{cmd:,} {it:s}{cmd:)}:
{it:input:}
{it:s}: 1 {it:x} 1
{it:output:}
{it:S}: 1 {it:x} 1
{it:result}: 1 {it:x} 1
{title:Diagnostics}
{p 4 4 2}
{cmd:st_macroexpand(}{it:s}{cmd:)} aborts with error if {it:s} is too long
(exceedingly unlikely) or if macro expansion fails (also unlikely).
{p 4 4 2}
{cmd:_st_macroexpand(}{it:S}{cmd:,} {it:s}{cmd:)} aborts with error if {it:s}
is too long.
{title:Source code}
{p 4 4 2}
Functions are built-in.
{title:Also see}
{p 4 13 2}
Manual: {hi:[M-5] st_macroexpand()}
{p 4 13 2}
Online: help for
{bf:{help m4_stata:[M-4] stata}}
{p_end}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -