全部版块 我的主页
论坛 计量经济学与统计论坛 五区 计量经济学与统计软件 Stata专版
9882 4
2007-10-22

请问在编程中  _rc 是什么意思??

在进行某些操作后

我用dis (_rc) 可以查看到_rc的数值

但又不是存在 ereturn list  或return list 中的

请问这是为什么?

_rc的数值又代表什么??

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2007-10-22 14:50:00



-----------------------------------------------------------------------------------------------------------
help for System Variables                                   manual:  [U] 16.4 System variables (_variables)
-----------------------------------------------------------------------------------------------------------

System Variables

    Expressions may also contain _variables (pronounced "underscore variables").  These are built in
    system variables that are created and updated by Stata.  They are called _variables because their
    names all begin with the underscore '_' character.

    The _variables are

    [eqno]_b[varname] (synonym:  [eqno]_coef[varname]) contains the value (to machine precision) of the
        coefficient on varname from the most recently fitted model (such as ANOVA, regression, Cox,
        logit, probit, multinomial logit, and the like).  See [U] 16.5 Accessing coefficients and
        standard errors for a complete description.

    _cons is always equal to the number 1 when used directly and refers to the intercept term when used
        indirectly, as in _b[_cons].

    _n contains the number of the current observation.

    _N contains the total number of observations in the dataset.

    _pi contains the value of pi to machine precision.

    _rc contains the value of the return code from the most recent capture command; see help capture.

    [eqno]_se[varname] contains the value (to machine precision) of the standard error of the coefficient
        on varname from the most recently fitted model (such as ANOVA, regression, Cox, logit, probit,
        multinomial logit, and the like).  See [U] 16.5 Accessing coefficients and standard errors for a
        complete description.

    The _n and _N variables are useful for indexing observations or generating sequences of numbers.  _n
    can act as a running counter within a by group and _N acts as the total number within each by group.

    _rc is useful for programmers, particularly if you want to test a command internal to a program   without having the program terminate.


Examples

    . by famid: gen sibs = _N
    . by famid: gen birtho = _N - _n + 1
    . display _pi
    . display cos(_pi)
    . gen x = cos(_pi/4*_n)
    . gen price2 = price[_n-1]

    . mvreg len disp gear_ratio = turn tru mpg wei
    . display [displ]_b[mpg]

    . mlogit rep gear_ratio turn tru
    . display [5]_b[turn]


Also see

    Manual:  [U] 16.4 System variables (_variables)

    Online:  help for by, generate, replace, subscripting


二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2007-10-22 19:34:00

_rc 是一个暂元,记录了错误信息的代码,主要在编程中使用。举一个简单的例子:

. sysuse auto,clear
(1978 Automobile Data)

. drop price2   /*由于price2 变量不存在,所以返回错误代码 r(111),stata停止工作*/
variable price2 not found
r(111);

. capture drop price2 /*使用capture命令可以保证无论命令正确与否,stata都可以继续执行后续命令*/

. dis _rc  /*因为上面那个命令有问题,所以capture在其暂元_rc中记录了错误代码*/
111

. capture drop price  /*这条命令可以正确执行,所以返回的错误代码是 0 */

. dis _rc
0

. cap verify price<0  /*不同的情况下,返回的错误大麦是不同的*/

. dis _rc
199

* 实际编程过程中,我们这样使用 _rc 命令:

local var price2
capture drop `var'
if _rc != 0{
  dis "`var' not found!"
}

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2014-3-31 10:24:59
多谢解答,收获很大。
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2021-1-25 00:25:50
arlionn 发表于 2007-10-22 19:34
_rc 是一个暂元,记录了错误信息的代码,主要在编程中使用。举一个简单的例子:. sysuse auto,clear(1978 A ...
哇,明白了,不得不说讲解的太清楚了,可谓经典的解释!!
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群