楼主: 如梦星河
4867 12

[数据管理求助] 请问如何求本行业出自身以外其他公司的中位数? [推广有奖]

  • 0关注
  • 0粉丝

已卖:2份资源

大专生

26%

还不是VIP/贵宾

-

威望
0
论坛币
23 个
通用积分
1.0000
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
344 点
帖子
12
精华
0
在线时间
77 小时
注册时间
2014-4-13
最后登录
2021-7-5

楼主
如梦星河 发表于 2018-8-2 19:05:38 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
请问如何求本行业除自身以外其他公司某变量的中位数?例如000001所在行业中,除000001以外,其他企业业绩的中位数。
二维码

扫码加我 拉你入群

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

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

关键词:000001 企业业绩 其他企业 本行业 中位数

沙发
18638292722 发表于 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 合用的!

7
如梦星河 发表于 2018-11-22 09:06:02
黃河泉 发表于 2018-11-22 08:11
rangestat 是可以与 by 合用的!
. bys year a SOE:rangestat (median) pay3 , interval(year 0 0) excludeself
rangestat may not be combined with by

老师您看,它是这样报错的

8
如梦星河 发表于 2018-11-22 09:12:17
黃河泉 发表于 2018-11-22 08:11
rangestat 是可以与 by 合用的!
好的老师,我知道了,我用rangestat (median) pay3 , by (year a SOE)interval(year 0 0) excludeself得出了结果

9
黃河泉 在职认证  发表于 2018-11-22 09:12:18
如梦星河 发表于 2018-11-22 09:06
. bys year a SOE:rangestat (median) pay3 , interval(year 0 0) excludeself
rangestat may not be  ...
请先看看 help rangestat,里面从来没有讲过你这样的作法!

10
sannian_ 发表于 2019-8-17 13:57:13
蓝色 发表于 2018-8-6 09:13
rangestat 命令帮助里面例子
探索了这个命令很久,但是仔细看完了红字下面的介绍后,完美解决了我的问题!无限感谢!!

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

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