全部版块 我的主页
论坛 计量经济学与统计论坛 五区 计量经济学与统计软件 Stata专版
7774 11
2014-03-19
悬赏 1000 个论坛币 已解决
"怎么在stata中实现一行数,比如50个数,的排列组合。或者具体一点,怎么实现这50个数的所有的组合,对于每一对组合,对其做商,再返回成一行数。"



最佳答案

jjjj6666 查看完整内容

you can use mata to generate all the permutation, but if you have 50 unique values, the number of variables will be 50!, which is impossible for stata to hold. The code is, suppose you have the data in var x mata j=0 st_view(X = ., ., "x") info = cvpermutesetup(X) while ((p=cvpermute(info)) != J(0,1,.)) { j++ x="p"+strofreal(j) st_addvar("float",x) st_store(.,x,p) } f ...
二维码

扫码加我 拉你入群

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

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

全部回复
2014-3-19 10:47:53
you can use mata to generate all the permutation, but if you have 50 unique values, the number of variables will be 50!, which is impossible for stata to hold.  The code is, suppose you have the data in var x

mata
j=0
st_view(X = ., ., "x")
info = cvpermutesetup(X)
while ((p=cvpermute(info)) != J(0,1,.)) {
                j++
                x="p"+strofreal(j)
                st_addvar("float",x)
                st_store(.,x,p)
}

for data from 1 to 6, the code will generate 720 extra variables, then you can loop for the pairs.  But your problem is based on 50 values, you can see how large 50! is, seems not realistic.

二维码

扫码加我 拉你入群

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

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

2014-3-19 14:43:55
没有看懂什么意思
如果是排列组合,percom命令可以实现。
二维码

扫码加我 拉你入群

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

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

2014-3-20 07:34:35
最好举个例子!
二维码

扫码加我 拉你入群

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

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

2015-1-3 03:45:39
ywh19860616 发表于 2014-3-19 14:43
没有看懂什么意思
如果是排列组合,percom命令可以实现。
combin x, k(2)                                          
combin x, k(3)
二维码

扫码加我 拉你入群

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

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

2019-12-5 22:35:16
ywh19860616 发表于 2014-3-19 14:43
没有看懂什么意思
如果是排列组合,percom命令可以实现。
你好,请问percom命令如何下载或安装呢?我折腾了好久,内部命令findit,search,ssc install都试过了,网页上也找了,还是没安装上。请赐教,谢谢!
二维码

扫码加我 拉你入群

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

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

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

说点什么

分享

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