📄 mf_st_global.hlp
字号:
{smcl}
{* 06apr2005}{...}
{cmd:help mata st_global()}
{hline}
{* index stata macros}{...}
{* index stata r()-class results}{...}
{* index stata e()-class results}{...}
{* index stata s()-class results}{...}
{* index stata c()-class results}{...}
{* index stata characteristics}{...}
{* index st_global()}{...}
{title:Title}
{p 4 28 2}
{bf:[M-5] st_global() -- Obtain strings from and put strings into global macros}
{title:Syntax}
{p 8 12 2}
{it:string scalar}
{cmd:st_global(}{it:string scalar name}{cmd:)}
{p 8 12 2}
{it:void}{bind: }
{cmd:st_global(}{it:string scalar name}{cmd:,}
{it:string scalar contents}{cmd:)}
{p 4 8 2}
where
{p 8 12 2}
1. {it:name} is to contain
{p_end}
{p 16 20 2}
a. global macro such as {cmd:"myname"}
{p_end}
{p 16 20 2}
b. {cmd:r()} macro such as {cmd:"r(names)"}
{p_end}
{p 16 20 2}
c. {cmd:e()} macro such as {cmd:"e(cmd)"}
{p_end}
{p 16 20 2}
d. {cmd:s()} macro such as {cmd:"s(vars)"}
{p_end}
{p 16 20 2}
e. {cmd:c()} macro such as {cmd:"c(current_date)"}
{p_end}
{p 16 20 2}
f. dataset characteristic such as {cmd:"_dta[date]"}
{p_end}
{p 16 20 2}
g. variable characteristic such as {cmd:"mpg[note]"}
{p 8 12 2}
2.
{cmd:st_global(}{it:name}{cmd:, "")} deletes, and it deletes even if
the {it:name} is not a macro.
For instance, perhaps {cmd:r(N)} is a numeric scalar;
{cmd:st_global(r(N), "")} will delete it.
Perhaps {cmd:e(X)} is matrix;
{cmd:st_global(e(X), "")} will delete it.
{title:Description}
{p 4 4 2}
{cmd:st_global(}{it:name}{cmd:)} returns the contents of the specified
Stata global.
{p 4 4 2}
{cmd:st_global(}{it:name}{cmd:,} {it:contents}{cmd:)} sets or resets the
contents of the specified Stata global. If the Stata global did not previously
exist, a new global is created. If the global did exist, the new contents
replace the old.
{title:Remarks}
{p 4 4 2}
Mata provides a suite of functions for obtaining and setting the contents of
global macros, local macros, saved results, etc. It can sometimes be
confusing to know which you should use. The following will help
{hline 70}
Stata component/action function call
{hline 70}
Local macro
obtain contents {it:contents}{cmd: = st_local("}{it:name}{cmd:")}
create/set/replace {cmd:st_local("}{it:name}{cmd:",} {it:contents}{cmd:)}
delete {cmd:st_local("}{it:name}{cmd:", "")}
{hline 70}
Global macro
obtain contents {it:contents}{cmd: = st_global("}{it:name}{cmd:")}
create/set/replace {cmd:st_global("}{it:name}{cmd:",} {it:contents}{cmd:)}
delete {cmd:st_global("}{it:name}{cmd:", "")}
{hline 70}
Global numeric scalar
obtain contents {it:value}{cmd: = st_numscalar("}{it:name}{cmd:")}
create/set/replace {cmd:st_numscalar("}{it:name}{cmd:",} {it:value}{cmd:)}
delete {cmd:st_numscalar("}{it:name}{cmd:", J(0,0,.))}
{hline 70}
Global string scalar
obtain contents {it:contents}{cmd: = st_strscalar("}{it:name}{cmd:")}
create/set/replace {cmd:st_strscalar("}{it:name}{cmd:",} {it:contents}{cmd:)}
delete {cmd:st_strscalar("}{it:name}{cmd:", J(0,0,""))}
{hline 70}
Global matrix
obtain contents {it:matrix} {cmd:= st_matrix("}{it:name}{cmd:")}
{it:rowlabel} {cmd:= st_matrixrowstripe("}{it:name}{cmd:")}
{it:collabel} {cmd:= st_matrixcolstripe("}{it:name}{cmd:")}
create/set/replace {cmd:st_matrix("}name}{cmd:",} {it:matrix}{cmd:)}
{cmd:st_matrixrowstripe("}name}{cmd:",} {it:rowlabel}{cmd:)}
{cmd:st_matrixcolstripe("}name}{cmd:",} {it:collabel}{cmd:)}
replace {cmd:st_replacematrix("}name}{cmd:",} {it:matrix}{cmd:)}
delete {cmd:st_matrix("}name}{cmd:", J(0,0,.))}
{hline 70}
Characteristic
obtain contents {it:contents}{cmd: = st_global("}{it:name}{cmd:[}{it:name}{cmd:]")}
create/set/replace {cmd:st_global("}{it:name}{cmd:[}{it:name}{cmd:]",} {it:contents}{cmd:)}
delete {cmd:st_global("}{it:name}{cmd:[}{it:name}{cmd:]", "")}
{hline 70}
{cmd:r()} results
macro
obtain contents {it:contents}{cmd: = st_global("r(}{it:name}{cmd:)")}
create/set/replace {cmd:st_global("r(}{it:name}{cmd:)",} {it:contents}{cmd:)}
numeric scalar
obtain contents {it:value}{cmd: = st_numscalar("r(}{it:name}{cmd:)")}
create/set/replace {cmd:st_numscalar("r(}{it:name}{cmd:)",} {it:value}{cmd:)}
matrix
obtain contents {it:matrix} {cmd:= st_matrix("r(}{it:name}{cmd:)")}
{it:rowlabel} {cmd:= st_matrixrowstripe("r(}{it:name}{cmd:)")}
{it:collabel} {cmd:= st_matrixcolstripe("r(}{it:name}{cmd:)")}
create/set/replace {cmd:st_matrix("r(}name}{cmd:)",} {it:matrix}{cmd:)}
{cmd:st_matrixrowstripe("r(}name}{cmd:)",} {it:rowlabel}{cmd:)}
{cmd:st_matrixcolstripe("r(}name}{cmd:)",} {it:collabel}{cmd:)}
replace {cmd:st_replacematrix("r(}name}{cmd:)",} {it:matrix}{cmd:)}
IN ALL CASES
delete {cmd:st_global("r(}{it:name}{cmd:)", "")}
to delete all of r() {cmd:st_rclear()}
{hline 70}
{cmd:e()} results
same as r() results, but code {cmd:e(}{it:name}{cmd:)} and {cmd:st_eclear()}
{hline 70}
{cmd:s()} results
macro
obtain contents {it:contents}{cmd: = st_global("s(}{it:name}{cmd:)")}
create/set/replace {cmd:st_global("s(}{it:name}{cmd:)",} {it:contents}{cmd:)}
delete {cmd:st_global("s(}{it:name}{cmd:)", "")}
delete all of s() {cmd:st_sclear()}
{hline 70}
{cmd:c()} results
macro
obtain contents {it:contents}{cmd: = st_global("c(}{it:name}{cmd:)")}
numeric scalar
obtain contents {it:value}{cmd: = st_numscalar("c(}{it:name}{cmd:)")}
{hline 70}
{p 8 8 2}
See {bf:{help mf_st_local:[M-5] st_local()}},
{bf:{help mf_st_numscalar:[M-5] st_numscalar()}},
{bf:{help mf_st_matrix:[M-5] st_matrix()}},
and
{bf:{help mf_st_rclear:[M-5] st_rclear()}}.
{title:Conformability}
{cmd:st_global(}{it:name}{cmd:)}:
{it:name}: 1 {it:x} 1
{it:result}: 1 {it:x} 1
{cmd:st_global(}{it:name}{cmd:,} {it:contents}{cmd:)}:
{it:name}: 1 {it:x} 1
{it:contents}: 1 {it:x} 1
{it:result}: {it:void}
{title:Diagnostics}
{p 4 4 2}
{cmd:st_global(}{it:name}{cmd:)} returns "" if the name contained in
{it:name} is not defined. {cmd:st_global(}{it:name}{cmd:)} aborts with
error if the name is malformed, such as {cmd:st_global("invalid name")}
{p 4 4 2}
{cmd:st_global(}{it:name}{cmd:,} {it:contents}{cmd:)} aborts with error if
the name contained in {it:name} is malformed.
Note that the maximum length of strings in Mata is significantly longer
than in Stata. {cmd:st_global()} truncates what is stored at the
appropriate maximum length if that is necessary.
{title:Source code}
{p 4 4 2}
Function is built-in.
{title:Also see}
{p 4 13 2}
Manual: {hi:[M-5] st_global()}
{p 4 13 2}
Online: help for
{bf:{help mf_st_rclear:[M-5] st_rclear()}};
{bf:{help m4_stata:[M-4] stata}}
{p_end}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -