楼主: 413024
10018 4

[求助][原创]请教高手关于_rc?? [推广有奖]

  • 0关注
  • 0粉丝

VIP+

已卖:83份资源

副教授

24%

还不是VIP/贵宾

-

威望
2
论坛币
19310 个
通用积分
0
学术水平
1 点
热心指数
2 点
信用等级
0 点
经验
3930 点
帖子
115
精华
0
在线时间
428 小时
注册时间
2007-4-22
最后登录
2015-12-20

楼主
413024 发表于 2007-10-22 10:52:00 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币

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

在进行某些操作后

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

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

请问这是为什么?

_rc的数值又代表什么??

二维码

扫码加我 拉你入群

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

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

关键词:请教高手 RETURN 是什么意思 list turn 求助 请教 高手 原创

沙发
蓝色 发表于 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


藤椅
arlionn 在职认证  发表于 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!"
}

已有 2 人评分学术水平 热心指数 信用等级 收起 理由
不读诗无以立 + 1 + 1 + 1 观点有启发
福建的小苗 + 1 + 1 + 1 我很赞同

总评分: 学术水平 + 2  热心指数 + 2  信用等级 + 2   查看全部评分

板凳
flynnfeng 发表于 2014-3-31 10:24:59
多谢解答,收获很大。

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

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群
GMT+8, 2026-1-19 01:03