全部版块 我的主页
论坛 计量经济学与统计论坛 五区 计量经济学与统计软件 Stata专版
30177 6
2011-12-31
我在用sum对一列数求和的时候,结果输出的是第一个数到最后一个数的累计求和的数列,我想引用最后的总和,请问怎么改?
二维码

扫码加我 拉你入群

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

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

全部回复
2011-12-31 14:35:41

. sysuse auto
(1978 Automobile Data)

. sum price

    Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
       price |        74    6165.257    2949.496       3291      15906

. return list

scalars:
                  r(N) =  74
              r(sum_w) =  74
               r(mean) =  6165.256756756757
                r(Var) =  8699525.974268789
                 r(sd) =  2949.495884768919
                r(min) =  3291
                r(max) =  15906
                r(sum) =  456229


. scalar total=r(sum)

. di total
456229
二维码

扫码加我 拉你入群

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

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

2011-12-31 14:36:38

Title

    [R] summarize -- Summary statistics


Syntax

        summarize [varlist] [if] [in] [weight] [, options]

    options           Description
    ---------------------------------------------------------------------------------------------
    Main
      detail          display additional statistics
      meanonly        suppress the display; calculate only the mean; programmer's option
      format          use variable's display format
      separator(#)    draw separator line after every # variables; default is separator(5)
      display_options control spacing and base and empty cells

    ---------------------------------------------------------------------------------------------
    varlist may contain factor variables; see fvvarlist.
    varlist may contain time-series operators; see tsvarlist.
    by is allowed; see [D] by.
    aweights, fweights, and iweights are allowed.  However, iweights may not be used with the
      detail option; see weight.


Menu

    Statistics > Summaries, tables, and tests > Summary and descriptive statistics > Summary
        statistics


Description

    summarize calculates and displays a variety of univariate summary statistics.  If no varlist
    is specified, summary statistics are calculated for all the variables in the dataset.

    Also see [R] ci for calculating the standard error and confidence intervals of the mean.


Options

        +------+
    ----+ Main +---------------------------------------------------------------------------------

    detail produces additional statistics, including skewness, kurtosis, the four smallest and
        four largest values, and various percentiles.

    meanonly, which is allowed only when detail is not specified, suppresses the display of
        results and calculation of the variance.  Ado-file writers will find this useful for fast
        calls.

    format requests that the summary statistics be displayed using the display formats associated
        with the variables rather than the default g display format; see [D] format.

    separator(#) specifies how often to insert separation lines into the output.  The default is
        separator(5), meaning that a line is drawn after every five variables.  separator(10)
        would draw a line after every 10 variables.  separator(0) suppresses the separation line.

    display_options:  vsquish, noemptycells, baselevels, allbaselevels; see [R] estimation
        options.


Examples

    . sysuse auto
    . summarize
    . summarize mpg weight
    . summarize mpg weight if foreign
    . summarize mpg weight if foreign, detail
    . summarize i.rep78


Saved results

    summarize saves the following in r():

    Scalars   
      r(N)           number of observations
      r(mean)        mean
      r(skewness)    skewness (detail only)
      r(min)         minimum
      r(max)         maximum
      r(sum_w)       sum of the weights
      r(p1)          1st percentile (detail only)
      r(p5)          5th percentile (detail only)
      r(p10)         10th percentile (detail only)
      r(p25)         25th percentile (detail only)
      r(p50)         50th percentile (detail only)
      r(p75)         75th percentile (detail only)
      r(p90)         90th percentile (detail only)
      r(p95)         95th percentile (detail only)
      r(p99)         99th percentile (detail only)
      r(Var)         variance
      r(kurtosis)    kurtosis (detail only)
      r(sum)         sum of variable
      r(sd)          standard deviation
二维码

扫码加我 拉你入群

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

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

2011-12-31 14:47:31
蓝色 发表于 2011-12-31 14:35
. sysuse auto
(1978 Automobile Data)
谢谢!但是我有十列数要求和 都这样做有点麻烦啊 用total怎么写命令呢 我是想用求到的和在进行别的运算
二维码

扫码加我 拉你入群

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

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

2012-1-1 21:48:38
用循环foreach
二维码

扫码加我 拉你入群

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

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

2012-5-17 09:22:45
不知道,我也有同样困惑
二维码

扫码加我 拉你入群

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

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

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

说点什么

分享

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