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

📄 syntax.hlp

📁 是一个经济学管理应用软件 很难找的 但是经济学学生又必须用到
💻 HLP
📖 第 1 页 / 共 2 页
字号:
{smcl}
{* 17feb2005}{...}
{cmd:help syntax}
{hline}

{title:Title}

{p2colset 5 19 21 2}{...}
{p2col :{hi:[P] syntax} {hline 2}}Parse Stata syntax{p_end}
{p2colreset}{...}


{title:Syntax}

{p 8 10 2}{cmd:syntax} {it:description_of_syntax}


{title:Description}

{pstd}
For a general discussion of the Stata language, see {help language}.

{pstd}
{cmd:syntax} provides an easy way to write programs that take input
according to standard Stata syntax.  {cmd:syntax} examines what the user typed
and attempts to match it to the syntax diagram.  If it does not match, an
error message is issued and the program is stopped (a nonzero return code is
returned).  If it does match, the individual components are stored in
particular local macros where you can subsequently access them.  For example,
in your program, you might code

	{cmd:program define myprog}
		{cmd:version {ccl stata_version}}
		{cmd:syntax [varlist] [if] [in] [, DOF(integer 50) Beta(real 1.0)]}
		{it:...}
		(program uses macros {cmd:`varlist'}, {cmd:`if'}, {cmd:`in'}, {cmd:`dof'}, and {cmd:`beta'})
		{it:...}
	{cmd:end}

{pstd}
If the user of {hi:myprog} typed

	{cmd:. myprog mpg weig if mpg>20}

    then

	local macro {cmd:`varlist'} would contain        "{hi:mpg weight}"
	local macro {cmd:`if'}      would contain        "{hi:if mpg>20}"
	local macro {cmd:`in'}      would contain        ""
	local macro {cmd:`dof'}     would default to     "{hi:50}"
	local macro {cmd:`beta'}    would default to     "{hi:1.0}"

{pstd}
Thus parsing is just a matter of understanding the kinds of things you can
type after the word {cmd:syntax} and where the results are stored.  The syntax
of the {cmd:syntax} command is outlined below.


{title:Syntax, continued}

{p 8 10 2}{cmd:syntax} {it:description_of_syntax}

{pstd}
where {it:description_of_syntax} may contain

	{it:{help syntax##description_of_varlist:description_of_varlist}}
	{it:{help syntax##description_of_namelist:description_of_namelist}}
	{it:{help syntax##description_of_anything:description_of_anything}}
	{it:{help syntax##description_of_if:description_of_if}}
	{it:{help syntax##description_of_in:description_of_in}}
	{it:{help syntax##description_of_using:description_of_using}}
	{it:{help syntax##description_of_=exp:description_of_=exp}}
	{it:{help syntax##description_of_weights:description_of_weights}}
	{it:{help syntax##description_of_options:description_of_options}}


{marker description_of_varlist}{...}
{title:description_of_varlist}

	type{col 29}{it:nothing}
     or
	optionally type{col 29}{cmd:[}
	then type one of{col 29}{cmd:varlist}  {cmd:varname}  {cmd:newvarlist}  {cmd:newvarname}
	optionally type{col 29}{cmd:(}{it:varlist_specifiers}{cmd:)}
	type{col 29}{cmd:]}     (if you typed {cmd:[} at the start)

    where {it:varlist_specifiers} are
	{cmd:default=none}
	{cmd:min=}{it:#}
	{cmd:max=}{it:#}
	{cmdab:num:eric}
	{cmdab:str:ing}
	{cmd:ts}
	{cmdab:gen:erate}        ({cmd:newvarlist} and {cmd:newvarname} only)

    Examples:
	{cmd:syntax varlist} {it:...}
	{cmd:syntax [varlist]} {it:...}
	{cmd:syntax varlist(min=2)} {it:...}
	{cmd:syntax varlist(max=4)} {it:...}
	{cmd:syntax varlist(min=2 max=4 numeric)} {it:...}
	{cmd:syntax [varlist(default=none)]} {it:...}
	{cmd:syntax newvarlist} {it:...}
	{cmd:syntax newvarlist(max=1)} {it:...}
	{cmd:syntax varname} {it:...}
	{cmd:syntax [varname]} {it:...}

{pstd}
If you type nothing, the command does not allow a varlist.

{pstd}
Typing {cmd:[} and {cmd:]} means the varlist is optional. 

{pstd}
{cmd:default=} specifies how the varlist is to be filled in when the
varlist is optional and the user does not specify it.  The default is to fill
it in with all the variables.  If {cmd:default=none} is specified, it is left
empty.

{pstd}
{cmd:min} and {cmd:max} specify the minimum and maximum number of
variables that may be specified.  Typing {cmd:varname} is equivalent to typing
{cmd:varlist(max=1)}.

{pstd}
{cmd:numeric} and {cmd:string} restrict the specified varlist to consist of
entirely numeric or entirely string variables.

{pstd}
{cmd:ts} allows the varlist to contain time-series operators.

{pstd}
{cmd:generate} specifies, in the case of {cmd:newvarlist} or
{cmd:newvarname}, that the new variables are to be created and filled in
with missing values.

{pstd}
After the {cmd:syntax} command, the resulting varlist is returned in
{cmd:`varlist'}.  If they are new variables (you coded {cmd:newvarname} or
{cmd:newvarlist}), the macro {cmd:typlist} is also defined, containing the
storage type of each of the new variables, listed one following the other.


{marker description_of_namelist}{...}
{title:description_of_namelist}

	type                {it:nothing}
     or
	optionally type     {cmd:[}
	then type one of    {cmd:namelist}  {cmd:name}
	optionally type{col 29}{cmd:(}{it:namelist_specifiers}{cmd:)}
	type{col 29}{cmd:]}    (if you typed {cmd:[} at the start)

    where {it:namelist_specifiers} are

	{cmd:name=}{it:name}
	{cmd:id="}{it:text}{cmd:"}
	{cmd:local}
	{cmd:min=}{it:#}                ({cmd:namelist} only)
	{cmd:max=}{it:#}                ({cmd:namelist} only)

    Examples:
	{cmd:syntax namelist} {it:...}
	{cmd:syntax [namelist]} {it:...}
	{cmd:syntax name(id="equation name")} {it:...}
	{cmd:syntax [namelist(id="equation name")]} {it:...}
	{cmd:syntax namelist(name=eqlist id="equation list")} {it:...}
	{cmd:syntax [name(name=eqname id="equation name")]} {it:...}
	{cmd:syntax namelist(min=2 max=2)} {it:...}

{pstd}
{cmd:namelist} is an alternative to {cmd:varlist}; it relaxes the restriction
that the names the user specifies be of variables.  {cmd:name} is a shorthand
for {cmd:namelist(min=1 max=1)}.

{pstd}
{cmd:namelist} is for use when you want the command to have the nearly
standard syntax of command name followed by a list of names (not necessarily
variable names) followed by {cmd:if}, {cmd:in}, {it:options}, etc.
For instance, perhaps the command is to be followed by a list of
variable-label names.

{pstd}
If you type nothing, the command does not allow a namelist.  Typing
{cmd:[} and {cmd:]} means the namelist is optional.  After the {cmd:syntax}
command, the resulting namelist is returned in {cmd:`namelist'}
unless {cmd:name=}{it:name} is specified; in which case, the result is
returned in {cmd:`}{it:name}{cmd:'}.

{pstd}
{cmd:id=} specifies the name of namelist and is used in error messages.  The
default is {cmd:id=namelist}.  If a namelist were required and {cmd:id=} was
not specified, and the user typed "{cmd:mycmd} {cmd:if} ..."  (omitting the
namelist), the error message would be "namelist required".  If you specified
{cmd:id="equation name"}, the error message would be "equation name required".

{pstd}
{cmd:name=} specifies the name of the local macro to receive the namelist;
not specifying the option is equivalent to specifying {cmd:name=namelist}.

{pstd}
{cmd:local} specifies that the names the user specifies are to satisfy the
naming convention for local macronames.  If this option is not specified,
standard naming convention is used (names may begin with a letter or
underscore, may thereafter also include numbers, and must not be longer than
32 characters).  If the user specifies an invalid name, an error message
will be issued.  If {cmd:local} is specified, specified names are allowed
to begin with numbers but may not be longer than 31 characters.


{marker description_of_anything}{...}
{title:description_of_anything}

	type                {it:nothing}
     or
	optionally type     {cmd:[}
	type                {cmd:anything}
	optionally type{col 29}{cmd:(}{it:anything_specifiers}{cmd:)}
	type{col 29}{cmd:]} if you typed {cmd:[} at the start.

    where {it:anything_specifiers} are

	{cmd:name=}{it:name}
	{cmd:id="}{it:text}{cmd:"}
	{cmd:equalok}
	{cmd:everything}

    Examples:
	{cmd:syntax anything} {it:...}
	{cmd:syntax [anything]} {it:...}
	{cmd:syntax anything(id="equation")} {it:...}
	{cmd:syntax [anything(id="equation")]} {it:...}
	{cmd:syntax anything(name=eqlist id="equation list")} {it:...}
	{cmd:syntax [anything(name=eqlist id="equation list")]} {it:...}
	{cmd:syntax anything(equalok)} {it:...}
	{cmd:syntax anything(everything)} {it:...}

{pstd}
{cmd:anything} is for use when you want the command to have the nearly
standard syntax of command name followed by something followed by {cmd:if},
{cmd:in}, {it:options}, etc.  For instance, perhaps the command is to be
followed by an expression or expressions, a list of numbers, etc.

{pstd}
If you type nothing, then the command does not allow an "anything".  Typing
{cmd:[} and {cmd:]} means the "anything" is optional.  After the {cmd:syntax}
command, the resulting "anything list" is returned in {cmd:`anything'}
unless {cmd:name=}{it:name} is specified; in which case, the result is
returned in {cmd:`}{it:name}{cmd:'}.

{pstd}
{cmd:id=} specifies the name of "anything" and is used only in error messages.
For instance, if {cmd:anything} were required and {cmd:id=} was not specified,
and the user typed "{cmd:mycmd} {cmd:if} ..."  (omitting the "anything"), the
error message would be "something required".  If you specified
{cmd:id="expression list"}, the error message would be "expression list
required".

{pstd}
{cmd:name=} specifies the name of the local macro to receive the "anything";
not specifying the option is equivalent to specifying {cmd:name=anything}.

{pstd}
{cmd:equalok} specifies that {cmd:=} is not to be treated as part of
{cmd:=}{it:exp} in subsequent standard syntax, but instead as part of the
{cmd:anything}.

{pstd}
{cmd:everything} specifies that {cmd:if}, {cmd:in}, and {cmd:using} are
not to be treated as part of standard syntax, but instead as part of
the {cmd:anything}.

{pstd}
{cmd:varlist}, {cmd:varname}, {cmd:namelist}, {cmd:name}, and {cmd:anything}
are alternatives; you may specify at most one.


{marker description_of_if}{...}
{title:description_of_if}

	type                {it:nothing}
     or
	optionally type     {cmd:[}
	type                {cmd:if}
	optionally type     {cmd:/}
	type                {cmd:]}      (if you typed {cmd:[} at the start)

    Examples:
	{cmd:syntax} {it:...} {cmd:if} {it:...}
	{cmd:syntax} {it:...} {cmd:[if]} {it:...}
	{cmd:syntax} {it:...} {cmd:[if/]} {it:...}
	{cmd:syntax} {it:...} {cmd:if/} {it:...}

{pstd}
If you type nothing, the command does not allow an {cmd:if} {it:exp}.

{pstd}
Typing {cmd:[} and {cmd:]} means that the {cmd:if} {it:exp} varlist is
optional.

{pstd}
After the {cmd:syntax} command, the resulting {cmd:if} {it:exp} is returned in
{cmd:`if'}.  This macro contains {cmd:if} followed by the expression, unless
you specified {cmd:/}; in which case, the macro contains just the expression.


{marker description_of_in}{...}
{title:description_of_in}

	type                {it:nothing}
     or
	optionally type     {cmd:[}
	type                {cmd:in}
	optionally type     {cmd:/}
	type                {cmd:]}      (if you typed {cmd:[} at the start)

    Examples:
	{cmd:syntax} {it:...} {cmd:in} {it:...}
	{cmd:syntax} {it:...} {cmd:[in]} {it:...}
	{cmd:syntax} {it:...} {cmd:[in/]} {it:...}
	{cmd:syntax} {it:...} {cmd:in/} {it:...}

{pstd}
If you type nothing, the command does not allow an {cmd:in} {it:range}.

{pstd}
Typing {cmd:[} and {cmd:]} means the {cmd:in} {it:range} is optional.

{pstd}
After the {cmd:syntax} command, the resulting {cmd:in} {it:range} is returned
in {cmd:`in'}.  The macro contains {cmd:in} followed by the range, unless you
typed {cmd:/}; in which case, the macro contains just the range.


{marker description_of_using}{...}
{title:description_of_using}

	type                {it:nothing}
     or
	optionally type     {cmd:[}
	type                {cmd:using}
	optionally type     {cmd:/}
	type                {cmd:]}      (if you typed {cmd:[} at the start)

    Examples:
	{cmd:syntax} {it:...} {cmd:using} {it:...}
	{cmd:syntax} {it:...} {cmd:[using]} {it:...}
	{cmd:syntax} {it:...} {cmd:[using/]} {it:...}
	{cmd:syntax} {it:...} {cmd:using/} {it:...}

{pstd}
If you type nothing, the command does not allow {cmd:using} {it:filename}.

{pstd}
Typing {cmd:[} and {cmd:]} means the {cmd:using} {it:filename} is optional.

{pstd}
After the {cmd:syntax} command, the resulting file is returned in
{cmd:`using'}.  The macro contains {cmd:using} followed by the filename in
quotes, unless you specified {cmd:/}; in which case, the macro contains just the
filename without quotes.


{marker description_of_=exp}{...}
{title:description_of_=exp}

	type                {it:nothing}
     or
	optionally type     {cmd:[}
	type                {cmd:=exp} or {cmd:=/exp}
	type                {cmd:]}      (if you typed {cmd:[} at the start)

    Examples:
	{cmd:syntax} {it:...} {cmd:=exp} {it:...}
	{cmd:syntax} {it:...} {cmd:[=exp]} {it:...}
	{cmd:syntax} {it:...} {cmd:[=/exp]} {it:...}
	{cmd:syntax} {it:...} {cmd:=/exp} {it:...}

{pstd}
If you type nothing, the command does not allow {cmd:=}{it:exp}.

{pstd}
Typing {cmd:[} and {cmd:]} means the {cmd:=}{it:exp} is optional.

{pstd}
After the {cmd:syntax} command, the resulting expression is returned in
{cmd:`exp'}.  The macro contains {cmd:=}, a space, and the expression, unless
you specified {cmd:/}; in which case, the macro contains just the expression.


{marker description_of_weights}{...}
{title:description_of_weights}

	type                {it:nothing}
     or
	type                {cmd:[}
	type any of         {cmdab:fw:eight}  {cmdab:aw:eight}  {cmdab:pw:eight}  {cmdab:iw:eight}
	optionally type     {cmd:/}
	type                {cmd:]}

    Examples:
	{cmd:syntax} {it:...} {cmd:[fweight]} {it:...}
	{cmd:syntax} {it:...} {cmd:[fweight pweight]} {it:...}
	{cmd:syntax} {it:...} {cmd:[pweight fweight]} {it:...}
	{cmd:syntax} {it:...} {cmd:[fweight pweight iweight/]} {it:...}

⌨️ 快捷键说明

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