📄 return.hlp
字号:
{smcl}
{* 28mar2005}{...}
{cmd:help ereturn}, {cmd:help return}, {cmd:help sreturn}{...}
{right:dialog: {dialog return_list:return/ereturn list}}
{hline}
{title:Title}
{p2colset 5 19 21 2}{...}
{p2col :{hi:[P] return} {hline 2}}Return saved results{p_end}
{p2col 5 26 28 2:{hi:[R] saved results} {hline 2}}Saved results{p_end}
{p2colreset}{...}
{title:Syntax}
{pstd}Return results stored in {hi:r()}
{p 8 15 2}{cmdab:ret:urn} {cmdab:li:st}
{p 8 15 2}{cmdab:ret:urn} {cmd:clear}
{p 8 15 2}{cmdab:ret:urn} {cmdab:sca:lar} {it:name} {cmd:=} {it:exp}
{p 8 15 2}{cmdab:ret:urn} {cmdab:loc:al} {it:name} {cmd:=} {it:exp}
{p 8 15 2}{cmdab:ret:urn} {cmdab:loc:al} {it:name} [{cmd:"}]{it:string}[{cmd:"}]
{p 8 15 2}{cmdab:ret:urn} {cmdab:mat:rix} {it:name} [{cmd:=}] {it:matname}
[{cmd:,} {cmd:copy}]
{p 8 15 2}{cmdab:ret:urn} {cmd:add}
Return results stored in {hi:e()}{right:(also see {helpb ereturn}) }
{p 8 16 2}{cmdab:eret:urn} {cmdab:li:st}
{p 8 16 2}{cmdab:eret:urn} {cmd:clear}
{p 8 16 2}{cmdab:eret:urn} {cmd:post} {it:b} {it:V} [{it:C}] [{cmd:,}
{cmdab:dep:name:(}{it:string}{cmd:)} {cmdab:o:bs:(}{it:#}{cmd:)}
{cmdab:d:of:(}{it:#}{cmd:)} {cmdab:e:sample:(}{it:varname}{cmd:)}]
{p 8 16 2}{cmdab:eret:urn} {cmdab:sca:lar} {it:name} {cmd:=} {it:exp}
{p 8 16 2}{cmdab:eret:urn} {cmdab:loc:al} {it:name} {cmd:=} {it:exp}
{p 8 16 2}{cmdab:eret:urn} {cmdab:loc:al} {it:name} [{cmd:"}]{it:string}[{cmd:"}]
{p 8 16 2}{cmdab:eret:urn} {cmdab:mat:rix} {it:name} [{cmd:=}] {it:matname}
[{cmd:,} {cmd:copy}]
{p 8 16 2}{cmdab:eret:urn} {cmd:repost} [{cmd:b =} {it:b}] [{cmd:V =} {it:V}]
[{cmd:,} {cmdab:e:sample:(}{it:varname}{cmd:)} {cmdab:ren:ame}]
{pstd}Return saved results in {hi:s()}
{p 8 16 2}{cmdab:sret:urn} {cmdab:li:st}
{p 8 16 2}{cmdab:sret:urn} {cmd:clear}
{p 8 16 2}{cmdab:sret:urn} {cmdab:loc:al} {it:name} {cmd:=} {it:exp}
{p 8 16 2}{cmdab:sret:urn} {cmdab:loc:al} {it:name} [{cmd:"}]{it:string}[{cmd:"}]
{title:Description}
{pstd}
Stata commands{hline 2}and new commands that you and others write{hline 2}can
be classified as follows:
{p 4 14 2}r-class:{space 2}general commands such as {helpb summarize}. Results
are returned in {hi:r()} and generally must be used before executing more
commands.
{p 14 14 2}{cmd:return list} lists results stored in {hi:r()}.
{cmd:return local}, {cmd:return scalar}, and {cmd:return matrix} save macros,
scalars, and matrices in {cmd:return()}. {cmd:return add} adds the current
{hi:r()} values to {cmd:return()}. {cmd:return clear} clears {cmd:return()}.
{cmd:return()} is local to the program. At the end of an r-class program,
items in {cmd:return()} are placed in {hi:r()} for final return.
{p 4 14 2}e-class:{space 2}estimation commands such as {helpb regress},
{helpb logistic}, etc., that fit statistical models. Such estimation
results stay around until the next model is fitted. Results are returned
in {hi:e()}.
{p 14 14 2}{cmd:ereturn list} lists results stored in {hi:e()}.
{cmd:ereturn local}, {cmd:ereturn scalar}, and {cmd:ereturn matrix} save
macros, scalars, and matrices in {hi:e()}. See {helpb ereturn} for
more details and information on the other subcommands.
{p 4 14 2}s-class: programming commands that assist in parsing. These commands
are relatively rare. Results are returned in {hi:s()}.
{p 14 14 2}{cmd:sreturn list} lists results stored in {hi:s()}.
{cmd:sreturn local} saves macros in {hi:s()}.
{p 4 14 2}n-class: commands that do not save results at all or, more correctly,
do not save "extra" results because where they save what they save is
explicitly specified. {helpb generate} and {helpb replace} are examples.
{pstd}
There is also a c-class, {hi:c()}, containing the values of system parameters
and settings, along with certain constants, such as the value of pi; see
{helpb creturn}. A program cannot be c-class.
{title:Options}
{p 4 8 2}
{cmd:copy} specified with {cmd:return matrix} indicates that the matrix is
to be copied, leaving the original in place. The default is to move the
matrix.
{pstd}See {helpb ereturn} for a description of the options to the
{cmd:ereturn} command.
{title:Examples}
{pstd}The following rclass command demonstrates returning results via
the {cmd:return} command:
{cmd:program define mysum, rclass}
{cmd:syntax varname}
{cmd:return local varname `varlist'}
{cmd:tempvar new}
{cmd:quietly {c -(}}
{cmd:count if `varlist'!=.}
{cmd:return scalar N = r(N)}
{cmd:gen double `new' = sum(`varlist')}
{cmd:return scalar sum = `new'[_N]}
{cmd:return scalar mean = return(sum)/return(N)}
{cmd:{c )-}}
{cmd:end}
{pstd}You can run this program and then list the returned results:
{cmd:. mysum mpg}
{cmd:. return list}
scalars:
r(mean) = {res:21.2972972972973}
r(sum) = {res:1576}
r(N) = {res:74}
macros:
r(varname) : {res:"mpg"}
{pstd}The values {hi:r(mean)}, {hi:r(sum)}, {hi:r(N)}, and {hi:r(varname)}
can now be referred to directly.
{cmd:. display "The variable is " r(varname) " with mean " r(mean)}
{res:The variable is mpg with mean 21.297297}
{title:Also see}
{psee}
Manual: {bf:[P] return},
{bf:[R] saved results}
{psee}
Online: {helpb _return}, {helpb ereturn}; {helpb program};
{helpb creturn}
{p_end}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -