楼主: qwer_1234
24032 7

statsby怎么用啊? [推广有奖]

  • 0关注
  • 0粉丝

小学生

35%

还不是VIP/贵宾

-

威望
0
论坛币
9573 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
102 点
帖子
9
精华
0
在线时间
0 小时
注册时间
2005-11-3
最后登录
2008-4-15

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币

我要获得回归的系数比如:

我要做一个简单的回归,y on x的,我要用statsby取得估计的系数,该怎么做呢?

clear
* 生成数据,x,y
drawnorm x e, n(100)
gen y=1+1*x+e
*   回归
reg y x
* 获取系数
statsby ....

[此贴子已经被作者于2008-4-11 7:12:23编辑过]

二维码

扫码加我 拉你入群

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

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

关键词:statsby stats draw Norm REG statsby

回帖推荐

whgyu 发表于5楼  查看完整内容

sysuse auto是调用stata附带的一个数据auto.dta. Stata里很多的例子都是用这个数据做的。foreigen是里面的一个变量。statsby是用在categorical variable上的。比如foreign有两个值0/1, statsby, by(foreigen): regress mpg gear turn就相当于两个回归:regress mpg gear turn if foreign==0regress mpg gear turn if foreign==1然后statsby把对应的系数存下来。这样你就会有一个两行的新数据foreign   _b[mpg] ...0  ...

arlionn 发表于6楼  查看完整内容

以下是引用qwer_1234在2008-4-11 7:54:00的发言:谢谢,蓝色,我看了help的,但还是不明白。特别是:Example: Collecting coefficients    . sysuse auto    . statsby, by(foreign): regress mpg gear turn这个 sysuse auto是不是可有可无啊?foreign 是一个变量吗? 我试过以下几种:cleardrawnorm x e, n(100) gen y=1+1*x+egen z=1reg y xstatsby by(x) :reg y xstatsby by(y) :reg y xstatsb ...

本帖被以下文库推荐

沙发
蓝色 发表于 2008-4-11 07:26:00 |只看作者 |坛友微信交流群

没有用过那个命令,但是你可以查查help啊

里面有例子,自己操作一下就知道了啊。下面就可stata里面的help的内容。看最后的例子。


help statsby                                                                                        dialog:  statsby
--------------------------------------------------------------------------------------------------------------------

Title

    [D] statsby -- Collect statistics for a command across a by list


Syntax

        statsby [exp_list] [, options ]:  command

    options                    description
    --------------------------------------------------------------------------------------------------------------
    Main
    * by(varlist [, missing])  equivalent to interactive use of by varlist:

    Options
      clear                    replace data in memory with results
      saving(filename, ...)    save results to filename; save statistics in double precision; save results to
                                 filename every # replications
      total                    include results for the entire dataset
      subsets                  include all combinations of subsets of groups

    Reporting
      nodots                   suppress the replication dots
      noisily                  display any output from command
      trace                    trace the command
      nolegend                 suppress table legend
      verbose                  display the full table legend

    Advanced
      basepop(exp)             restrict initializing sample to exp; seldom used
      force                    do not check for svy commands; seldom used
      forcedrop                retain only observations in by() groups when calling command; seldom used
    --------------------------------------------------------------------------------------------------------------
    * by() is required on the dialog box because statsby is useful to the interactive user only when using by().
    All weight types supported by command are allowed except pweights; see weight.


Description

    statsby collects statistics from command across a by() list.  Typing

        . statsby exp_list , by(varname): command

    executes command for each group identified by varname, building a dataset of the associated values from the
    expressions in exp_list.  The resulting dataset replaces the current dataset, unless the saving() option is
    supplied.

    command defines the statistical command to be executed.  Most Stata commands and user-written programs can be
    used with statsby, as long as they follow standard Stata syntax and allow the if qualifier.  The by prefix
    cannot be part of command.

    exp_list specifies the statistics to be collected from the execution of command.  The expressions in exp_list
    follow the grammar given in exp_list.  If no expressions are given, exp_list assumes a default depending upon
    whether command changes results in e() and r().  If command changes results in e(), the default is _b.  If
    command changes results in r() (but not e()), the default is all the scalars posted to r().  It is an error
    not to specify an expression in exp_list otherwise.


Options

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

    by(varlist [, missing]) specifies a list of existing variables that would normally appear in the by varlist:
        section of the command if you were to issue the command interactively.  By default, statsby ignores groups
        in which one or more of the by() variables is missing.  Alternatively, missing causes missing values to be
        treated like any other values in the by() groups, and results from the entire dataset are included with
        use of the subsets option.  If by() is not specified, command will be run on the entire dataset. varlist
        can contain both numeric and string variables.

        +---------+
    ----+ Options +-----------------------------------------------------------------------------------------------

    clear specifies that it is okay to replace the data in memory, even though the current data have not been
        saved to disk.

    saving(filename [, suboptions]) creates a Stata data file (.dta file) consisting of (for each statistic in
        exp_list) a variable containing the replicates.

        See help prefix_saving_option, for details about suboptions.

    total specifies that command be run on the entire dataset, in addition to the groups specified in the by()
        option.

    subsets specifies that command be run for each group defined by any combination of the variables in the by()
        option.

        +-----------+
    ----+ Reporting +---------------------------------------------------------------------------------------------

    nodots suppresses display of the replication dots. By default, one dot character is printed for each by()
        group. A red `x' is printed if command returns with an error or one of the values in exp_list is missing.

    noisily causes the output of command to be displayed for each by() group.  This option implies the nodots
        option.

    trace causes a trace of the execution of command to be displayed.  This option implies the noisily option.

    nolegend suppresses the display of the table legend, which identifies the rows of the table with the
        expressions they represent.

    verbose requests that the full table legend be displayed.  By default, coefficients and standard errors are
        not displayed.

        +----------+
    ----+ Advanced +----------------------------------------------------------------------------------------------

    basepop(exp) specifies a base population that statsby uses to evaluate the command and to set up for
        collecting statistics.  The default base population is the entire dataset, or the dataset specified by any
        if or in conditions specified on the command.

        One situation where basepop() is useful is collecting statistics over the panels of a panel dataset by
        using an estimator that works for time series, but not panel data, e.g.,

            . statsby, by(mypanels) basepop(mypanels==2): arima ...

    force suppresses the restriction that command not be a svy command.  statsby does not perform subpopulation
        estimation for survey data, so it should not be used with svy.  statsby reports an error when it
        encounters svy in command if the force option is not specified.  This option is seldom used, so use it
        only if you know what you are doing.

    forcedrop forces statsby to drop all observations except those in each by() group before calling command for
        the group.  This allows statsby to work with user-written commands that completely ignore if and in but do
        not return an error when either is specified.  forcedrop is seldom used.


Example: Collecting coefficients

    . sysuse auto
    . statsby, by(foreign): regress mpg gear turn


Example: Collecting both coefficients and standard errors using a time-series estimator with panel data

    . webuse grunfeld, clear
    . tsset company year
    . statsby _b _se, basepop(company==1) by(company):  arima invest mvalue kstock, ar(1)


Example: Collecting results saved in r-class macros

    . sysuse auto, clear
    . statsby mean=r(mean) sd=r(sd) size=r(N), by(rep78):  summarize mpg


Also see

    Manual:  [D] statsby

    Online:  [P] postfile, [D] collapse, [R] bootstrap, [R] jackknife, [R] permute, [D] by

使用道具

藤椅
qwer_1234 发表于 2008-4-11 07:54:00 |只看作者 |坛友微信交流群

谢谢,蓝色,我看了help的,但还是不明白。

特别是:

Example: Collecting coefficients

    . sysuse auto
    . statsby, by(foreign): regress mpg gear turn

这个 sysuse auto是不是可有可无啊?

foreign 是一个变量吗? 

我试过以下几种:

clear
drawnorm x e, n(100)
gen y=1+1*x+e
gen z=1
reg y x

statsby by(x) :reg y x

statsby by(y) :reg y x

statsby by(z) :reg y x

都提示说:
no; data in memory would be lost

都快要疯掉了哦。

使用道具

板凳
蓝色 发表于 2008-4-11 07:59:00 |只看作者 |坛友微信交流群

sysuse auto

是打开stata软件安装是自带的数据auto文件

不打开文件怎么执行命令啊

使用道具

报纸
whgyu 发表于 2008-4-11 08:05:00 |只看作者 |坛友微信交流群
sysuse auto是调用stata附带的一个数据auto.dta. Stata里很多的例子都是用这个数据做的。foreigen是里面的一个变量。

statsby是用在categorical variable上的。比如foreign有两个值0/1,

statsby, by(foreigen): regress mpg gear turn

就相当于两个回归:

regress mpg gear turn if foreign==0
regress mpg gear turn if foreign==1

然后statsby把对应的系数存下来。这样你就会有一个两行的新数据
foreign   _b[mpg] ...
0           ...
1           ...

你看到的那个提示是因为你产生的x,y,z数据没有存,所以stata不能再产生新的数据(就是上面那两行)。你只要用statsby ...., clear就行了。

我不太清楚你想干什么。在你自己的例子中,x, y, z都是连续变量,by(x)没有意义。

已有 1 人评分论坛币 学术水平 热心指数 收起 理由
crystal8832 + 10 + 1 + 1 热心帮助其他会员

总评分: 论坛币 + 10  学术水平 + 1  热心指数 + 1   查看全部评分

使用道具

地板
arlionn 在职认证  发表于 2008-4-11 08:31:00 |只看作者 |坛友微信交流群
以下是引用qwer_1234在2008-4-11 7:54:00的发言:

谢谢,蓝色,我看了help的,但还是不明白。

特别是:

Example: Collecting coefficients

    . sysuse auto
    . statsby, by(foreign): regress mpg gear turn

这个 sysuse auto是不是可有可无啊?

foreign 是一个变量吗? 

我试过以下几种:

clear
drawnorm x e, n(100)
gen y=1+1*x+e
gen z=1
reg y x

statsby by(x) :reg y x

statsby by(y) :reg y x

statsby by(z) :reg y x

都提示说:
no; data in memory would be lost

都快要疯掉了哦。

clear
drawnorm x e, n(100)
gen y=1+1*x+e
gen z=x>0.5
reg y x
save data1.dta, replace

statsby _b[x], by(z) :reg y x

执行statsby命令前,必须保证数据已经存储。因为该命令执行后数据内容将发生变化。

*------------结果----------------------------

. statsby _b[x], by(z) :reg y x
(running regress on estimation sample)

      command:  regress y x
      _stat_1:  _b[x]
           by:  z

Statsby groups
----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5
..

.
end of do-file

. list

     +--------------+
     | z    _stat_1 |
     |--------------|
  1. | 0   1.175667 |
  2. | 1    1.43738 |
     +--------------+

[此贴子已经被作者于2008-4-11 8:32:04编辑过]

已有 4 人评分论坛币 学术水平 热心指数 信用等级 收起 理由
小虾米705 + 1 + 1 + 1 观点有启发
earing64 + 1 + 1 + 1 精彩帖子
lsssl524 + 5 + 5 + 5 精彩帖子
crystal8832 + 10 + 1 + 1 精彩帖子

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

使用道具

7
蓝色 发表于 2008-4-11 08:58:00 |只看作者 |坛友微信交流群

stata有用的命令太多了

看来的总结一下了。

这个命令从来没有用过呢。

使用道具

8
gaowenjing18 发表于 2016-1-26 18:14:14 |只看作者 |坛友微信交流群
谢谢分享!

使用道具

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

本版微信群
加好友,备注jltj
拉您入交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-4-28 06:15