📄 m2_version.hlp
字号:
{smcl}
{* 11mar2005}{...}
{cmd:help m2 version}
{hline}
{* index version control}{...}
{* index version tt}{...}
{title:Title}
{p 4 4 2}
{bf:[M-2] version -- Version control}
{title:Syntax}
{p 4 4 2}
Syntax 1:
. {cmd:version} {it:#}[{cmd:.}{it:#}]
. {cmd:mata:}
: ...
: {cmd:function} {it:name}{cmd:(}...{cmd:)}
: {cmd:{c -(}}
: ...
: {cmd:{c )-}}
: ...
: {cmd:end}
{p 4 4 2}
Syntax 2:
: {cmd:function} {it:name}{cmd:(}...{cmd:)}
: {cmd:{c -(}}
: {cmd:version} {it:#}[{cmd:.}{it:#}]
: ...
: {cmd:{c )-}}
{title:Description}
{p 4 4 2}
In syntax 1, Stata's {bf:{help version:[P] version}} command sets the
version before entering Mata. This specifies both the compiler and library
versions to be used. Syntax 1 is recommended.
{p 4 4 2}
In syntax 2, Mata's {cmd:version} command sets the version of the library
functions that are to be used. Syntax 2 is rarely used.
{title:Remarks}
{p 4 4 2}
Remarks are presented under the headings
{bf:Purpose of version control}
{bf:Recommendations for do-files}
{bf:Recommendations for ado-files}
{bf:Compile-time and run-time versioning}
{title:Purpose of version control}
{p 4 4 2}
Mata is under continual development, which means not only that new features
are being added, but sometimes means that old features change how they work.
Old features changing how they work is supposedly an improvement -- it
generally is -- but that also means old programs might
stop working or, worse, work differently.
{p 4 4 2}
{cmd:version} provides the solution.
{p 4 4 2}
If you are working interactively, nothing said here matters.
{p 4 4 2}
If you use Mata in do-files or ado-files, we recommend that you set
{cmd:version} before entering Mata.
{title:Recommendations for do-files}
{p 4 4 2}
The recommendation for do-files that use Mata is the same as for do-files that
do not use Mata: Specify the version number of the Stata you are using on the
top line:
{hline 50} myfile.do {hline 3}
{cmd:version 9.0}
...
{hline 50} myfile.do {hline 3}
{p 4 4 2}
To determine the number that should appear after {cmd:version}, type
{cmd:about} at the Stata prompt:
. {cmd:about}
Stata/SE 9.0
[{it:remaining output omitted}]
{p 4 4 2}
We are using Stata 9.0.
{p 4 4 2}
Coding {cmd:version} {cmd:9} will not benefit us today but, in the
future, we will be able to rerun our do-file and obtain the same results.
{p 4 4 2}
By the way, a do-file is any file that you intend to execute using
Stata's {cmd:do} or {cmd:run} commands, regardless of the file suffix.
Many users (us included) save Mata source code in {cmd:.mata} files and then
type {cmd:do} {it:myfile}{cmd:.mata} to compile.
{cmd:.mata} files are do-files; we include the {cmd:version} line:
{hline 48} myfile.mata {hline 3}
{cmd:version 9.0}
{cmd:mata:}
...
{cmd:end}
{hline 48} myfile.mata {hline 3}
{title:Recommendations for ado-files}
{p 4 4 2}
Mata functions may be included in ado-files; see {bf:{help m1_ado:[M-1] ado}}.
In such files, set {cmd:version} before entering Mata along with, as usual,
setting the version at the top of your program:
{hline 49} myfile.ado {hline 3}
program myfile
{cmd:version 9.0} <- {it:as usual}
...
end
{cmd:version 9.0} <- {it:new}
{cmd:mata:}
...
{cmd:end}
{hline 49} myfile.ado {hline 3}
{p 4 4 2}
{title:Compile-time and run-time versioning}
{p 4 4 2}
What follows is detail. We recommend following the recommendations
above in all cases.
{p 4 4 2}
There are actually two version numbers that matter -- the version number
set at the time of compilation, which affects how the source code is
interpreted, and the version of the libraries used to supply subroutines
at the time of execution.
{p 4 4 2}
The {cmd:version} command which we used in the previous sections is
in fact Stata's
{bf:{help version:[P] version}} command, and it sets both versions:
. {cmd:version 9.0}
. {cmd:mata:}
: {cmd:function example()}
: {cmd:{c -(}}
: ...
: {cmd:{c )-}}
: {cmd:end}
{p 4 4 2}
In the above, we compile {cmd:example()} using the version 9.0 syntax of the
Mata language,
and any functions {cmd:example()} calls will be the 9.0 version of those
functions. Setting {cmd:version} {cmd:9.0} before entering Mata ensured
all of that.
{p 4 4 2}
In the following example, we compile using version 9.0 syntax,
and use version 9.2 functions:
. {cmd:version 9.0}
. {cmd:mata:}
: {cmd:function example()}
: {cmd:{c -(}}
: {cmd:version 9.2}
: ...
: {cmd:{c )-}}
: {cmd:end}
{p 4 4 2}
In the following example, we compile using version 9.2 syntax,
and use version 9.0 functions:
. {cmd:version 9.2}
. {cmd:mata:}
: {cmd:function example()}
: {cmd:{c -(}}
: {cmd:version 9.0}
: ...
: {cmd:{c )-}}
: {cmd:end}
{p 4 4 2}
It is, however, very rare that you will want to compile and execute at
different version levels.
{title:Also see}
{p 4 13 2}
Manual: {hi:[M-2] version}
{p 4 13 2}
Online: help for
{bf:{help mf_callersversion:[M-5] callersversion()}};
{bf:{help m2_intro:[M-2] intro}}
{p_end}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -