楼主: jianlamhua
99363 78

[一般统计问题] 如何把pearson系数矩阵和spearman系数矩阵合并?   [推广有奖]

11
denver 发表于 2009-6-30 22:56:12
我一般的做法是使用excel处理。先将输出结果用文本向导导入excel,如果是上三角的话,就再复制一下,用选择性粘贴中的转置选项将其转为上三角即可,但关于显著性水平的画星星,恐怕还得手工来过。

12
jixi1299 发表于 2010-3-28 08:10:28
也学这个,谢谢啦~~~~~~~~~~~~~~~~~~~~~~~~~~~
hehe&o

13
arlionn 在职认证  发表于 2010-3-28 08:36:43
加星号的问题,请参见:
http://www.pinggu.org/bbs/b121i32761p14.html

14
arlionn 在职认证  发表于 2010-3-28 08:36:50
加星号的问题,请参见:
http://www.pinggu.org/bbs/b121i32761p14.html




Example:

. sysuse nlsw88, clear
(NLSW, 1988 extract)


. pwcorr_a grade wage hours ttl_exp  tenure age
             |    grade     wage    hours  ttl_exp   tenure      age
-------------+------------------------------------------------------
       grade |   1.000   
        wage |   0.325***  1.000   
       hours |   0.087***  0.159***  1.000   
     ttl_exp |   0.198***  0.265***  0.230***  1.000   
      tenure |   0.123***  0.178***  0.161***  0.577***  1.000   
         age |  -0.033    -0.036*   -0.028     0.124***  0.074***  1.000

15
voodoo 发表于 2010-3-28 20:17:52
以下程序主体用9楼sungmoo的代码,然后用estout程序包更加方便地获得格式化的输出(包括小数点位数、tab、rtf、excel等):

// check if -estout- is installed
capt which estout
if _rc ssc inst estout
// get data
sysuse auto.dta, clear
// collect correlation matrices
corr trunk weight length
matrix matpe = r(C)
spearman trunk weight length
matrix matsp = r(Rho)
matrix both = matpe
// combine the matrices
local I = rowsof(matpe)
forval i = 1/`I' {
local j1 = `i' + 1
forval j = `j1'/`I' {
  matrix both[`i',`j'] = matsp[`i',`j']
}
}
// display and save the result in specified format, - help esttab -
mat l both
esttab matrix(both, fmt(3)) using example, nomtitle rtf

个人认为estout程序包的功能非常强大,值得大家好好看看。
巫毒上传,必属佳品!
坛友下载,三思后行!

16
voodoo 发表于 2010-3-28 22:01:40
想要加星号和格式化的输出,试试(加红部分可以因需调整,其它部分最好不要改动):
// check if -estout- is installed
capt which estout
if _rc ssc inst estout

// clear stored estimates
eststo clear

// get data
sysuse auto, clear     // your .dta file here

// main: collect, display and save well-formated correlation matrices
local vlist trunk weight length    // your varlist here
local upper
local lower `vlist'
foreach v of local vlist {
    estpost correlate `v' `lower'
    foreach m in b rho p count {
        matrix `m' = e(`m')
    }
    if "`upper'"!="" {        // compute -spearman- with -corr-
                preserve
                tempvar `v'
                egen ``v'' = rank(`v')
                replace `v' = ``v''
                foreach var of local upper {
                        tempvar `var'
                        egen ``var'' = rank(`var')
                        replace `var' = ``var''
                }
                estpost correlate `v' `upper'
        foreach m in b rho p count {
            matrix `m' = e(`m'), `m'
        }
                restore
    }
    ereturn post b
    foreach m in rho p count {
        quietly estadd matrix `m' = `m'
    }
    eststo `v'
    local lower: list lower - v
    local upper `upper' `v'
}
esttab, nonumbers mtitles noobs not    // display
esttab using example, replace rtf nonumbers mtitles noobs not   // for use in Word
已有 8 人评分经验 论坛币 学术水平 热心指数 信用等级 收起 理由
Happy如初 + 1 + 1 + 1 精彩帖子
我爱爱德华 + 1 + 1 + 1 精彩帖子
V_ere + 5 + 5 + 5 精彩帖子
zdw515 + 1 + 1 + 1 精彩帖子
Sunknownay + 100 + 10 + 1 + 1 + 1 热心帮助其他会员
无尘第二 + 1 + 1 + 1 对论坛有贡献
dxystata + 20 好的意见建议
chke3 + 1 实用

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

巫毒上传,必属佳品!
坛友下载,三思后行!

17
saudada 发表于 2010-4-12 11:03:26
sungmoo 发表于 2009-5-13 10:41
mat a=(0,0\1,0)mat c=a#matpe+a'#matsp*这个可以省一步
對不起......請問一下,我分別跑出pearson與spearman後,

分別執行 est stroe m1 與 est store m2,再執行

mat a=(0,0\1,0)
mat c=a#m1+a'#m2

stata出現m1 not found的訊息,請問我儲存有問題嗎?謝謝!

18
sungmoo 发表于 2010-4-12 14:53:53
saudada 发表于 2010-4-12 11:03 分別執行 est stroe m1 與 est store m2
est sto不是用来生成矩阵的吧?

19
saudada 发表于 2010-4-12 19:46:40
大大您好:

執行以下指令,出現錯誤,麻煩請指正,謝謝您!

pwcorr x1 x2 x3
mat pe=r(Rho)
spearman x1 x2 x3
mat sp=r(Rho)
mat a=(0,0\1,0)
mat b=(0,1\0,0)
mat c=a#pe+b#sp

此時出現「conformability error」,請問哪裡出問題了呢?thanks!

20
chke3 发表于 2010-11-16 14:37:56
很好,受教了!非常感谢!

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

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