楼主: lhjnju
44155 10

[数据管理求助] stata中的r和scarlar什么意思怎么用 [推广有奖]

  • 0关注
  • 4粉丝

教师

已卖:55份资源

硕士生

71%

还不是VIP/贵宾

-

威望
0
论坛币
30528 个
通用积分
2.1555
学术水平
2 点
热心指数
3 点
信用等级
1 点
经验
2726 点
帖子
85
精华
0
在线时间
155 小时
注册时间
2005-8-21
最后登录
2025-4-3

楼主
lhjnju 发表于 2016-4-29 16:51:17 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
我在STATA中使用时,经常发现很多人用这两个函数。但我查阅了书也没发现这两个怎么用:
一个是r。例如:sysuse auto,clear              sum price,meanonly          gen xx=r(mean).那么,这里r(mean)中的“r”怎么用的?什么意思?
二是scalar.例如sysuse auto,clear
reg price length weight   
  est store  reg1
esttab reg1 using test.rtf, se scalars(N r2 F)
这里的ereturn和scalar到底是什么东东?怎么使用啊?

请好心人教我。谢谢非常感激!
二维码

扫码加我 拉你入群

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

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

关键词:Stata tata scar ARL CAR 好心人 store price

沙发
lhjnju 发表于 2016-4-29 17:18:18
再比如:接上面例子--
scalar gamma=r(mean)-2
这个scalar命令以前从来没有见过,到底是个什么样的命令?

藤椅
蓝色 发表于 2016-4-29 17:40:10
Title

    [P] return -- Return stored results


Syntax

    Return results for general commands, stored in r()

        return list [, all]

        return clear

        return scalar name = exp

        return local name = exp

        return local name ["]string["]

        return matrix name [=] matname [, copy]

        return add


    Return results for estimation commands, stored in e()

        ereturn list [, all]

        ereturn clear

        ereturn post [b [V [Cns]]] [weight] [, depname(string) obs(#) dof(#) esample(varname) properties(string)]

        ereturn scalar name = exp

        ereturn local name = exp

        ereturn local name ["]string["]

        ereturn matrix name [=] matname [, copy]

        ereturn repost [b = b] [V = V] [Cns = Cns] [weight] [, esample(varname) properties(string) rename]


    Return results for parsing commands, stored in s()

        sreturn list

        sreturn clear

        sreturn local name = exp

        sreturn local name ["]string["]


    where b, V, and Cns are matnames, which is the name of an existing matrix.

    fweights, aweights, iweights, and pweights are allowed; see weight.


Description

    Results of calculations are stored by many Stata commands so that they can be easily accessed and substituted into subsequent commands.  This entry
    summarizes for programmers how to store results.  If your interest is in using previously stored results, see [R] stored results.

    Stata commands -- and new commands that you and others write -- can be classified as follows:

    r-class:  general commands such as summarize.  Results are returned in r() and generally must be used before executing more commands.

              return list lists results stored in r().  return local, return scalar, and return matrix store macros, scalars, and matrices in return().
              return add adds the current r() values to return().  return clear clears return().  return() is local to the program.  At the end of an
              r-class program, items in return() are placed in r() for final return.

    e-class:  estimation commands such as regress, logistic, etc., that fit statistical models.  Such estimation results stay around until the next model
              is fit.  Results are returned in e().

              ereturn list lists results stored in e().  ereturn local, ereturn scalar, and ereturn matrix store macros, scalars, and matrices in e().
              See [P] ereturn for more details and information on the other subcommands.

    s-class:  programming commands that assist in parsing.  These commands are relatively rare.  Results are returned in s().

              sreturn list lists results stored in s().  sreturn local stores macros in s().

    n-class:  commands that do not store results at all or, more correctly, do not store "extra" results because where they store what they store is
              explicitly specified.  generate and replace are examples.

    There is also a c-class, c(), containing the values of system parameters and settings, along with certain constants, such as the value of pi; see [P]
    creturn.  A program cannot be c-class.


Options

    all is for use with return list or ereturn list.  all specifies that hidden and historical stored results be listed along with the usual stored
        results.  This option is seldom used.  See Using hidden and historical stored results and Programming hidden and historical stored results under
        Remarks and examples of [P] return for more information.  These sections are written in terms of return list, but everything said there applies
        equally to ereturn list.

        all is not allowed with sreturn list because s() does not allow hidden or historical results.

    copy specified with return matrix or ereturn matrix indicates that the matrix is to be copied; that is, the original matrix should be left in place.
        The default is to "steal" or "rename" the existing matrix, which is fast and conserves memory.

    depname(string) is for use with ereturn post.  It supplies the name of the dependent variable to appear in the estimation output.  The name specified
        need not be the name of an existing variable.

    obs(#) is for use with ereturn post.  It specifies the number of observations on which the estimation was performed.  This number is stored in e(N),
        and obs() is provided to simply for convenience.  Results are no different from those for ereturn post followed by ereturn scalar N = #.

    dof(#) is for use with ereturn post.  It specifies the number of denominator degrees of freedom to be used with t and F statistics and so is used in
        calculating significance levels and confidence intervals.  The number specified is stored in e(df_r), and dof() is provided simply for
        convenience.  Results are no different from those for ereturn post followed by ereturn scalar df_r = #.

    esample(varname) is for use with ereturn post and ereturn repost.  It specifies the name of a 0/1 variable that is to become the e(sample) function.
        varname must contain 0 and 1 values only, with 1 indicating that the observation is in the estimation subsample.  ereturn post and ereturn repost
        will be able to execute a little more quickly if varname is stored as a byte variable.

        varname is dropped from the dataset, or more correctly, it is stolen and stashed in a secret place.

    properties(string) specified with ereturn post or ereturn repost sets the e(properties) macro.  By default, e(properties) is set to b V if
        properties() is not specified.

    rename is for use with the b = b syntax of ereturn repost.  All numeric estimation results remain unchanged, but the labels of b are substituted for
        the variable and equation names of the already posted results.


Examples

    The following r-class command demonstrates returning results via the return command:

        program mysum, rclass
                syntax varname
                return local varname `varlist'
                tempvar new
                quietly {
                        count if !missing(`varlist')
                        return scalar N = r(N)
                        gen double `new' = sum(`varlist')
                        return scalar sum = `new'[_N]
                        return scalar mean = return(sum)/return(N)
                }
        end

    You can run this program and then list the returned results:

        . sysuse auto
        . mysum mpg
        . return list

        scalars:
               r(mean)     =  21.2972972972973
               r(sum)      =  1576
               r(N)        =  74

        macros:
               r(varname)  : "mpg"

    The values r(mean), r(sum), r(N), and r(varname) can now be referred to directly.

        . display "The variable is " r(varname) " with mean " r(mean)
        The variable is mpg with mean 21.297297
已有 2 人评分学术水平 热心指数 信用等级 收起 理由
18140548118 + 1 + 1 + 1 精彩帖子
xiliuyuan + 1 + 1 + 1 精彩帖子

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

板凳
byx438995846 发表于 2019-3-23 13:30:22
scalar(N r2 F),就是在显示结果时,显示样本数、r2、F统计量。特别在回归结果呈现时,可以将你想要显示的命令放在scalar()中。

报纸
哈哈哈我是谁 发表于 2019-5-13 23:42:22
r(mean)中的r意思是标量

地板
pkuser 发表于 2021-8-18 10:40:23
蓝色 发表于 2016-4-29 17:40
Title

     return -- Return stored results
以为是评论下拉菜单,没想到是个点踩,抱歉抱歉,新人初来乍到不太熟悉网页操作,请问大家要怎样才能取消点踩啊?

7
yyy521chh 发表于 2022-6-4 10:58:44
蓝色 发表于 2016-4-29 17:40
Title

     return -- Return stored results
还是没看懂r(N)输出的是什么?

8
慕容纤杨 在职认证  发表于 2022-6-11 22:51:13
yyy521chh 发表于 2022-6-4 10:58
还是没看懂r(N)输出的是什么?
应该是样本数。

Stata 命令分为三种类型:
  
     * (1) r-class  与模型估计无关的命令; 如,summary
     * (2) e-class  与模型估计有关的命令; 如,regress
     * (3) s-class  其它命令;             如,list
     * (4) c-class  存储系统参数

  *- 显示留存值的方法:
     * r-class:  return  list
     * e-class:  ereturn list
     * s-class:  sreturn list
     * c-class:  creturn list

  *- 留存值分为四种类型:
     * 单值:  如,r(mean), r(max), r(N), e(r2), e(F)
     * 矩阵:  如,e(b), e(V)
     * 暂元:  如,e(cmd), e(depvar)
     * 函变量:如,e(sample)

这是连玉君stata课程里面的讲解
已有 1 人评分论坛币 学术水平 热心指数 信用等级 收起 理由
yizhou1573 + 5 + 1 + 1 + 1 精彩帖子

总评分: 论坛币 + 5  学术水平 + 1  热心指数 + 1  信用等级 + 1   查看全部评分

9
Zuoyihui 发表于 2022-11-20 16:41:47
yyy521chh 发表于 2022-6-4 10:58
还是没看懂r(N)输出的是什么?
是样本数,r(mean)是平均值

10
季初初 发表于 2024-3-8 21:25:41
慕容纤杨 发表于 2022-6-11 22:51
应该是样本数。

Stata 命令分为三种类型:
感谢大佬,救我狗命,我一直以为r是在回归里的,我说怎么找不到

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

本版微信群
加好友,备注jltj
拉您入交流群
GMT+8, 2025-12-31 05:00