⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mf_stata.hlp

📁 是一个经济学管理应用软件 很难找的 但是经济学学生又必须用到
💻 HLP
字号:
{smcl}
{* 06apr2005}{...}
{cmd:help mata stata()}
{hline}
{* index stata()}{...}
{* index _stata()}{...}
{* index Stata, execute command}{...}

{title:Title}

{p 4 4 2}
{bf:[M-5] stata() -- Execute Stata command}


{title:Syntax}

{p 8 12 2}
{it:void}{bind:        }
{cmd:stata(}{it:cmd}{cmd:)}

{p 8 12 2}
{it:void}{bind:        }
{cmd:stata(}{it:cmd}{cmd:,}
{it:nooutput}{cmd:)}

{p 8 12 2}
{it:void}{bind:        }
{cmd:stata(}{it:cmd}{cmd:,}
{it:nooutput}{cmd:,}
{it:nomacroexpand}{cmd:)}


{p 8 12 2}
{it:real scalar}
{cmd:_stata(}{it:cmd}{cmd:)}

{p 8 12 2}
{it:real scalar}
{cmd:_stata(}{it:cmd}{cmd:,}
{it:nooutput}{cmd:)}

{p 8 12 2}
{it:real scalar}
{cmd:_stata(}{it:cmd}{cmd:,}
{it:nooutput}{cmd:,}
{it:nomacroexpand}{cmd:)}


{p 4 4 2}
where

		{it:cmd}:  {it:string scalar}

           {it:nooutput}:  {it:real scalar}

      {it:nomacroexpand}:  {it:real scalar}


{title:Description}

{p 4 4 2}
{cmd:stata(}{it:cmd}{cmd:)}
executes the Stata command contained in the string scalar {it:cmd}.
Output from the command appears at the terminal, and any macros 
contained in {it:cmd} are expanded.

{p 4 4 2}
{cmd:stata(}{it:cmd}{cmd:,} {it:nooutput}{cmd:)}
does the same thing, but if {it:nooutput}!=0, 
output produced by the execution is not displayed.
{cmd:stata(}{it:cmd}{cmd:,} {cmd:0)} is equivalent to 
{cmd:stata(}{it:cmd}{cmd:)}.

{p 4 4 2}
{cmd:stata(}{it:cmd}{cmd:,} {it:nooutput}{cmd:,} 
{it:nomacroexpand}{cmd:)}
does the same thing, but, before execution, suppresses expansion of any macros 
contained in {it:cmd} if 
{it:nomacroexpand}!=0.
{cmd:stata(}{it:cmd}{cmd:,} {cmd:0,} {cmd:0)} is equivalent to 
{cmd:stata(}{it:cmd}{cmd:)}.

{p 4 4 2}
{cmd:_stata()} repeats the syntaxes of {cmd:stata()}.  The difference 
is that, whereas {cmd:stata()} aborts with error if the execution results in a 
nonzero return code, {cmd:_stata()} returns the resulting return code.


{title:Remarks}

{p 4 4 2}
The command you execute may invoke a process which causes another instance
of Mata to be invoked.  For instance, Stata program {it:A} calls Mata 
function {it:m1()}, which executes {cmd:stata()} to invoke Stata program 
{it:B}, which in turn calls Mata function {it:m2()}, which ...

{p 4 4 2}
{cmd:stata(}{it:cmd}{cmd:)} and {cmd:_stata(}{it:cmd}{cmd:)}
execute {it:cmd} at the current run level.  This means any
local macros refer to local macros in the caller's space.  Consider the
following

	{cmd:program example}
		...
		{cmd:local x = "value from A"}
		{cmd:mata: myfunc()}
		{cmd:display "`x'"}
		...
	{cmd:end}

	{cmd}mata void myfunc()
	{c -(}
		stata(`"local x = "new value""')
	{c )-}{txt}

{p 4 4 2}
After {cmd:example} executes {cmd:mata: myfunc()}, {cmd:`x'} will be "new
value".

{p 4 4 2}
That {cmd:stata()} and {cmd:_stata()} work that way was intentional:  Mata
functions have the ability to modify the caller's environment so that they may
create temporary variables for the caller's use, etc., and you only have to
exercise a little caution.  Executing {cmd:stata()} functions to run other
ado-files and programs will cause no problems because other ado-files and
programs create their own new environment in which temporary variables, 
local macros, etc., are private.

{p 4 4 2}
Relatedly, do not use {cmd:stata()} or {cmd:_stata()} to execute a
multiline command or to execute the first line of what could be 
considered a multiline command.  Once the first line is executed, 
Stata will fetch the remaining lines from the caller's environment.
For instance, consider 

	{hline 50} myfile.do {hline 3}
	{cmd}mata void myfunc()
	{c -(}
		stata("if (1==1) {")
	{c )-}

	mata: myfunc()
	display "hello"
	{c )-}{txt}
	{hline 64}

{p 4 4 2}
In the example above, {cmd:myfunc()} will consume the {cmd:display}
{cmd:"hello"} and {cmd:{c )-}} lines.


{title:Conformability}

{p 4 8 2}
{cmd:stata(}{it:cmd}{cmd:,} {it:nooutput}{cmd:,} 
{it:nomacroexpand}{cmd:)}:
{p_end}
                        {it:cmd}:  1 {it:x} 1
                   {it:nooutput}:  1 {it:x} 1  (optional)
              {it:nomacroexpand}:  1 {it:x} 1  (optional)
                     {it:result}:  {it:void}

{p 4 8 2}
{cmd:stata(}{it:cmd}{cmd:,} {it:nooutput}{cmd:,} 
{it:nomacroexpand}{cmd:)}:
{p_end}
                        {it:cmd}:  1 {it:x} 1
                   {it:nooutput}:  1 {it:x} 1  (optional)
              {it:nomacroexpand}:  1 {it:x} 1  (optional)
                     {it:result}:  1 {it:x} 1


{title:Diagnostics}

{p 4 4 2}
{cmd:stata()} aborts with error if {it:cmd} is too long (exceedingly 
unlikely), if macro expansion fails, or if execution results in a 
nonzero return code.

{p 4 4 2}
{cmd:_stata()} aborts with error if {it:cmd} 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] stata()}

{p 4 13 2}
Online:  help for 
{bf:{help mata_stata:[M-3] mata stata}};
{bf:{help m4_stata:[M-4] stata}}
{p_end}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -