全部版块 我的主页
论坛 计量经济学与统计论坛 五区 计量经济学与统计软件 Stata专版
4930 12
2018-08-02
请问如何求本行业除自身以外其他公司某变量的中位数?例如000001所在行业中,除000001以外,其他企业业绩的中位数。
二维码

扫码加我 拉你入群

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

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

全部回复
2018-8-3 22:40:08
drop if id=000001
bysort sic:egen medvar=mediation(var)
id是你的公司代码 sic 是行业代码

二维码

扫码加我 拉你入群

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

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

2018-8-6 09:13:45
   rangestat 命令帮助里面例子




Median investment of other firms in a given year

    Some problems are hard to solve in Stata without a loop. You can easily calculate the median
    investment from all firms in any given year using a single egen call:

        --------------------------- example do-file content ---------------------------
        webuse grunfeld, clear
        bysort year: egen m = median(invest)
        --------------------------------------------------------------------------------
        (click to run)

    but there is no equally easy way to get an observation-specific median calculated using all
    observations within the group except the one from the current observation.  A naive brute force
    solution is to loop over observations:

        --------------------------- example do-file content ---------------------------
        webuse grunfeld, clear
        gen double mexclude = .
        quietly forvalues i=1/`=_N' {
          sum invest if year == year[`i'] & company != company[`i'], detail
          replace mexclude = r(p50) in `i'
        }
        list in 10/20
        --------------------------------------------------------------------------------
        (click to run)

    However, this is much slower than the egen direct solution and will become painfully slow as the
    number of observations increases.

    With rangestat, all you need is

        --------------------------- example do-file content ---------------------------
        webuse grunfeld, clear
        rangestat (median) invest, interval(year 0 0) excludeself
        list in 10/20
        --------------------------------------------------------------------------------
        (click to run)

    Note that the rangestat interval can be degenerate, as is the case above. Setting both low and high to
    zero will have the effect of selecting, for the current observation, all (and only) observations that
    have the same year. As the excludeself option is specified, the value of the variable invest for each
    current observation will be ignored.


二维码

扫码加我 拉你入群

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

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

2018-8-12 09:23:05
二维码

扫码加我 拉你入群

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

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

2018-11-21 23:38:37
蓝色 发表于 2018-8-6 09:13
rangestat 命令帮助里面例子
好的,非常感谢!那如果我想添加分组变量该怎么加呢,rangestat不能与bys连用,比如说我想求某个公司每年在所在行业中除了本身以外的中位数?
二维码

扫码加我 拉你入群

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

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

2018-11-22 08:11:43
如梦星河 发表于 2018-11-21 23:38
好的,非常感谢!那如果我想添加分组变量该怎么加呢,rangestat不能与bys连用,比如说我想求某个公司每年 ...
rangestat 是可以与 by 合用的!
二维码

扫码加我 拉你入群

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

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

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

说点什么

分享

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