楼主: wating2003
3560 6

弱弱地请教一下:sort的功能 [推广有奖]

  • 1关注
  • 0粉丝

博士生

35%

还不是VIP/贵宾

-

威望
0
论坛币
6 个
通用积分
15.0182
学术水平
2 点
热心指数
2 点
信用等级
2 点
经验
667 点
帖子
79
精华
0
在线时间
457 小时
注册时间
2007-4-9
最后登录
2024-9-11

楼主
wating2003 发表于 2011-1-2 10:03:55 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
想问一下 ,如果有很多变量 eg: a, b, c,d,e, f, g, h ......, 当用sort的时候,是否以一行行的观测值来重排的?
也就是说当我用
sort a b
这个指令会导致其余变量(c d e f g h)的混乱吗?
还是一定要用
sort a b, stable?
手册上说stable不常用,因为会让运行速度变慢很多

好像我解释得有点混乱呢 。。。。大概意思就是想知道sort a b后, a1,a2,a3 原先对应的其他变量是否仍在同一行?

谢谢
二维码

扫码加我 拉你入群

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

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

关键词:SOR Stable Table ABLE ABL 请教 功能 sort

沙发
abc7759abc 发表于 2011-1-2 10:31:39
可以查一下。。
历史是个什么玩意儿~

藤椅
wating2003 发表于 2011-1-4 07:12:31
谁有比较确定的答案吗? 因为我的数据很多, 抽查了几个好象没什么问题。。。。。。但是如果是不变的话, stable这个功能还要来干嘛??

板凳
蓝色 发表于 2011-1-4 07:28:06
wating2003 发表于 2011-1-4 07:12
谁有比较确定的答案吗? 因为我的数据很多, 抽查了几个好象没什么问题。。。。。。但是如果是不变的话, stable这个功能还要来干嘛??
help和manual中的解释是最有用的
为什么不看看呢
sort.pdf (115.64 KB)




Option
    stable specifies that observations with the same values of the variables in varlist keep the same relative
        order in the sorted data that they had previously.  For instance, consider the following data:
                                                      x  b
                                                      3  1
                                                      1  2
                                                      1  1
                                                      1  3
                                                      2  4
        Typing sort x without the stable option produces one of the following 6 orderings.
                                x  b  |  x  b  |  x  b  |  x  b  |  x  b  |  x  b
                                1  2  |  1  2  |  1  1  |  1  1  |  1  3  |  1  3
                                1  1  |  1  3  |  1  3  |  1  2  |  1  1  |  1  2
                                1  3  |  1  1  |  1  2  |  1  3  |  1  2  |  1  1
                                2  4  |  2  4  |  2  4  |  2  4  |  2  4  |  2  4
                                3  1  |  3  1  |  3  1  |  3  1  |  3  1  |  3  1
        Without the stable option, the ordering of observations with equal values of varlist is randomized.
        With sort x, stable, you will always get the first ordering and never the other five.
        If your intent is to have the observations sorted first on x and then on b within tied values of x (the
        fourth ordering above), you should type sort x b rather than sort x, stable.
        stable is seldom used, and, when specified, causes sort to execute more slowly.

报纸
wating2003 发表于 2011-1-4 10:38:15
4# 蓝色


先谢谢版主的解答 :)
我之前看过的, 我明白例子说的, 只是不是很确定在变量多过2的时候,比如变量: a, b, c,d,e, f, g, h ......,
当我用sort a b 时,在相同的a b值里,其余变量(c d e f g h) 是以一行行的方式随机排列吗(randomized by row rather than randomized within each individual variable)?

PS 我测试过了, 不用stable不会导致数据混乱,所以stable很少需要用到, 只会拖慢速度。

地板
hantaofly 发表于 2012-10-5 11:41:11
wating2003 发表于 2011-1-4 10:38
4# 蓝色
我用stata10,sort一个数据之后其余的数据就凌乱了,所以stable还是有用的@@

7
wating2003 发表于 2012-12-20 01:39:33
hantaofly 发表于 2012-10-5 11:41
我用stata10,sort一个数据之后其余的数据就凌乱了,所以stable还是有用的@@
你指的是每行数据变了么?
比如有数据
company          month     return             price
firm1                    1             3                   1firm1                    2             2                   2
firm2                    1             2                   3
firm2                    2             2                   4
firm3                    1             1                   5
firm3                    2             1                   6

sort company return后, 应该变成
company          month     return             price
firm1                    2             2                   2
firm1                    1             3                   1
firm2                    1             2                   3
firm2                    2             2                   4
firm3                    1             1                   5
firm3                    2             1                   6



如果是像下面这样就凌乱了
company          month     return             price
firm1                    2             2                   1
firm1                    1             3                   2
firm2                    1             2                   3
firm2                    2             2                   4
firm3                    1             1                   5
firm3                    2             1                   6



你确定出现凌乱情况了么? :) 或者你能不能把你凌乱的情况举个例子给我看看^^谢谢



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

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