全部版块 我的主页
论坛 计量经济学与统计论坛 五区 计量经济学与统计软件 Stata专版
43373 10
2016-04-29
我在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到底是什么东东?怎么使用啊?

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

扫码加我 拉你入群

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

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

全部回复
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
二维码

扫码加我 拉你入群

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

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

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

扫码加我 拉你入群

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

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

2019-5-13 23:42:22
r(mean)中的r意思是标量
二维码

扫码加我 拉你入群

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

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

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

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

扫码加我 拉你入群

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

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

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

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