楼主: xtcdw
12842 21

[其他] 请教:怎么求n个变量两两间的协方差? [推广有奖]

11
xtcdw 发表于 2012-4-9 11:37:17
sungmoo 发表于 2012-4-9 11:06
有没有clear?
有啊

12
sungmoo 发表于 2012-4-9 12:53:13
xtcdw 发表于 2012-4-9 11:37
有啊
我运行的结果没有问题。你把你的数据及操作过程贴一下。

13
xtcdw 发表于 2012-4-9 13:26:12
sungmoo 发表于 2012-4-9 12:53
我运行的结果没有问题。你把你的数据及操作过程贴一下。
这是原始数据:
stkcd        r
1        .0749
1        -.0321
1        .0129
1        .0219
1        .0998
1        .1005
1        .0221
......
操作代码:
bys stkcd:gen i=_n
reshape wide r,i(i) j(stkcd)
cor r*,c
mat r=r(c)
clear
svmat r
outsheet using r.xls
运行结果:
协方差已经算出来了,下面是导出时出的问题
. mat r=r(c)

.
. clear

.
. svmat r
number of observations will be reset to 1
Press any key to continue, or Break to abort
obs was 0, now 1

.
. outsheet using r.xls

14
sungmoo 发表于 2012-4-9 13:58:31
mat r=r(c)
问题出在这里:这里的c须大写。

r(C)
. svmat r
number of observations will be reset to 1
Press any key to continue, or Break to abort
obs was 0, now 1
这只是描述,最终结果取决于矩阵r的内容。

15
xtcdw 发表于 2012-4-9 14:36:17
sungmoo 发表于 2012-4-9 13:58
问题出在这里:这里的c须大写。

r(C)
大写了还是不行,还是出现下面的问题
svmat r
number of observations will be reset to 1
Press any key to continue, or Break to abort
obs was 0, now 1
数据集里的结果是:
r1
.
和用r(c)的结果一样


16
sungmoo 发表于 2012-4-9 14:44:21
贴出一部分你的代表性数据

17
xtcdw 发表于 2012-4-9 14:47:45
这是一部分数据

18
sungmoo 发表于 2012-4-9 15:03:24
xtcdw 发表于 2012-4-9 14:47
这是一部分数据
*就所给的数据而言,以下可以得到结果:
bys stkcd:gen i=_n
reshape wide r,i(i) j(stkcd)
cor r*,c
mat r=r(C)
clear
svmat r
outsheet using r.xls
已有 1 人评分学术水平 热心指数 信用等级 收起 理由
ywh19860616 + 1 + 1 + 1 kindly

总评分: 学术水平 + 1  热心指数 + 1  信用等级 + 1   查看全部评分

19
xtcdw 发表于 2012-4-9 15:28:26
sungmoo 发表于 2012-4-9 15:03
*就所给的数据而言,以下可以得到结果:
bys stkcd:gen i=_n
reshape wide r,i(i) j(stkcd)
那就不太清楚是什么问题了~非常感谢你对这个问题的解答

20
sungmoo 发表于 2012-4-9 15:45:31
clear
mat l r
svmat r
*加这一步,看看是什么结果?

已有 1 人评分学术水平 热心指数 信用等级 收起 理由
xtcdw + 1 + 1 + 1 好的意见建议

总评分: 学术水平 + 1  热心指数 + 1  信用等级 + 1   查看全部评分

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

本版微信群
加好友,备注jltj
拉您入交流群
GMT+8, 2026-2-3 19:59