楼主: mb34527
21707 10

[数据管理求助] stata关于剔除两端极值方法(在线等) [推广有奖]

  • 0关注
  • 0粉丝

学前班

60%

还不是VIP/贵宾

-

威望
0
论坛币
10 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
36 点
帖子
3
精华
0
在线时间
0 小时
注册时间
2014-6-23
最后登录
2015-10-20

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
老师推荐我用stata先将数据分组归类成从1%-100%组,然后将落在1%和100%的值删掉,然后再做回归分析,想问下大神们这要怎么写代码?第一步分组,第二步删除的代码。谢谢大家~~(老师不推荐用winsor的方法,因为数据整理拉平滑以后会对结果有影响。)

二维码

扫码加我 拉你入群

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

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

关键词:Stata tata 在线等 winsor 数据整理 回归分析 在线 影响

沙发
小斜 学生认证  发表于 2015-10-20 14:16:15 |只看作者 |坛友微信交流群
用winsor命令,这个命令每次只能处理一个变量。更高级的是winsor2,一次同时处理多个变量。如果不知道怎么写命令,你可以help winsor或者help winsor2,学习一下。

使用道具

藤椅
mb34527 发表于 2015-10-20 14:18:27 |只看作者 |坛友微信交流群
小斜 发表于 2015-10-20 14:16
用winsor命令,这个命令每次只能处理一个变量。更高级的是winsor2,一次同时处理多个变量。如果不知道怎么写 ...
我知道winsor这个方法,但是老师不推荐我用这个,整理拉平滑了以后,对数据影响太大了,不过还是谢谢你~

使用道具

板凳
mb34527 发表于 2015-10-20 15:49:25 |只看作者 |坛友微信交流群
顶一下上去

使用道具

报纸
hiderm 发表于 2015-10-20 20:17:23 |只看作者 |坛友微信交流群
mb34527 发表于 2015-10-20 14:18
我知道winsor这个方法,但是老师不推荐我用这个,整理拉平滑了以后,对数据影响太大了,不过还是谢谢你~


在winsor2 命令中,只要添加 trim 选项,就可以实现你老师要求的剔除离群值(trime)而不是缩尾(winsor)的功能

参见 help winsor2

Syntax

    winsor2 varlist [if] [in], [ suffix(string) replace trim cuts(# #) by(groupvar) label ]

Description

    winsor2 winsorize or trim (if trim option is specified) the variables in varlist at particular percentiles specified by option cuts(#1 #2).  In defult, new variables will be generated with a suffix "_w" or "_tr", which can be changed by specifying suffix() option.  The replace option replaces the variables with their winsorized or trimmed ones.

                +---------------------------------------------+
    ----+ Difference between winsorizing and trimming +----

    Winsorizing is not equivalent to simply excluding data, which is a simpler procedure, called trimming or truncation. In a trimmed estimator, the extreme values are discarded; in a Winsorized estimator, the extreme values are instead replaced by certain percentiles, specified by option cuts(# #).  For details, see winsor (if installed), trimmean (if installed).

    For example, you type the following commands to get the 1th and 99th percentiles of variable wage, 1.930993 and 38.70926, respectively.

        . sysuse nlsw88, clear
        . sum wage, detail

    In defult, winsor2 winsorize wage at 1th and 99th percentiles,

        . winsor2 wage, replace cuts(1 99)

    which can be done by hands:

        . replace wage=1.930993 if wage<1.930993
        . replace wage=38.70926 if wage>38.70926

    Note that, values smaller than the 1th percentile is repalce by the 1th percentile, and the similar thing is done with the 99th percentile.

    Things change when -trim- option is specified:

        . winsor2 wage, replace cuts(1 99) trim

    which can also be done by hands:

        . replace wage=. if wage<1.930993
        . replace wage=. if wage>38.70926

    In this case, we discard values smaller than 1th percentile or greater than 99th percentile.  This is trimming.



Options

    suffix(string) specifies the suffix of the new variables. The defult is "_w" or "_tr" (when trim specified).

    replace replaces the variables with their winsorized or trimmed counterpart.  Can not be specified with suffix(string).

    trim trims the variables.

    cuts(# #) specifies the percentiles at which the data is winsorized or trimmed.  cuts(1 99) (the default) means winsor (trim) at 1th and 99th percentile. Specify cuts(1 99) or cuts(99 1) makes no difference.

    by(groupvar) the winsor or trim is done within each group specified by groupvar.


Examples

        *- winsor at (p1 p99), get new variable "wage_w"
        .  sysuse nlsw88, clear
        .  winsor2 wage

        *- winsor 3 variables at 0.5th and 99.5th percentiles, and overwrite the old variables
        .  winsor2 wage age hours, cuts(0.5 99.5) replace

        *- winsor 3 variables at (p1 p99), gen new variables with suffix _win, and add variable labels
        .  winsor2 wage age hours, suffix(_win) label

        *- left-winsorizing only, at 1th percentile
        .  winsor2 wage, cuts(1 100)

        *- right-trimming only, at 99th percentile
        .  winsor2 wage, cuts(0 99) trim

        *- winsor variables at (p1 p99) by (industry), overwrite the old variables
        .  winsor2 wage hours, replace by(industry)
已有 5 人评分经验 论坛币 学术水平 热心指数 信用等级 收起 理由
sky捉迷藏 + 1 + 1 + 1 对论坛有贡献
北方的北方有极光 + 1 + 1 + 1 精彩帖子
happy_287422301 + 100 热心帮助其他会员
夏目贵志 + 5 + 1 热心帮助其他会员
Stakiny + 1 + 1 + 1 热心帮助其他会员

总评分: 经验 + 5  论坛币 + 100  学术水平 + 3  热心指数 + 4  信用等级 + 3   查看全部评分

使用道具

地板
离天三尺三 发表于 2015-10-25 16:48:12 |只看作者 |坛友微信交流群
hiderm 发表于 2015-10-20 20:17
在winsor2 命令中,只要添加 trim 选项,就可以实现你老师要求的剔除离群值(trime)而不是缩尾(winso ...

使用道具

7
黑色星期八 发表于 2015-10-26 20:45:42 |只看作者 |坛友微信交流群
hiderm 发表于 2015-10-20 20:17
在winsor2 命令中,只要添加 trim 选项,就可以实现你老师要求的剔除离群值(trime)而不是缩尾(winso ...
好专业啊,赞

使用道具

8
553436459 发表于 2015-11-17 14:32:22 来自手机 |只看作者 |坛友微信交流群
mb34527 发表于 2015-10-20 14:18
我知道winsor这个方法,但是老师不推荐我用这个,整理拉平滑了以后,对数据影响太大了,不过还是谢谢你~
那如果有负值呢?怎么去极值?

使用道具

9
zlsir 发表于 2017-4-1 16:02:30 |只看作者 |坛友微信交流群
请问这样做的目的是?有没有这种类似做法的文献呢?

使用道具

10
月上蟾 发表于 2018-1-23 21:13:28 |只看作者 |坛友微信交流群
zlsir 发表于 2017-4-1 16:02
请问这样做的目的是?有没有这种类似做法的文献呢?
我是在用工业企业数据库的时候看到很多文章都这样处理过工业企业数据。文章的话Competition and Corporate Tax Avoidance: Evidence from Chinese Industrial Firms这篇里对工业数据库的处理就是去除了前后各0.5%的极端值

使用道具

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

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

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

GMT+8, 2024-6-1 19:56