全部版块 我的主页
论坛 计量经济学与统计论坛 五区 计量经济学与统计软件 Stata专版
2081 1
2017-02-24
初学stata,编写程序,运行显示 invalid ·2',求纠错
capture program drop nemenyi
program define nemenyi
version 12.0
local g =`1'
if (`g'== 3 | `g'== 4){
if `g' ==3{
local n1 = `2'
local n2 = `3'
local n3 = `4'
local Rs1 = `5'
local Rs2 = `6'
local Rs3 = `7'
local H =`8'
local Hc = `9'

local N = `n1'+`n2'+`n3'
local r1 = `Rs1' / `n1'
local r2 = `Rs2'/ `n2'
local r3 = `Rs3' / `n3'
local C = `H'/ `Hc'

local x12 =( `r1' -`r2' ) 2/( (`N' *(`N' +1) / 12) * ( 1/ `n1' +1/ `n2')*`C')
local x13 =( `r1' -`r3' ) 2/( (`N' *(`N' +1) / 12) * ( 1/ `n1' +1/ `n3')*`C')
local x23 =( `r2' -`r3' ) 2/( (`N'*(`N' +1) / 12) * ( 1/ `n2 ' +1/ `n3')*`C')
local p12 = chiprob( 2, `x12')
local p13 = chiprob( 2, `x13')
local p23 = chiprob( 2, `x23')

di newline(1)
di " Nemenyi test of 3 Groups"
di "--------------------------- "
di "Group chi2 P value "
di "--------------------------- "
di " 1 and 2" in ye %9. 4f `x12' in ye %9. 4f `p12'
di " 1 and 3" in ye %9. 4f `x13' in ye %9. 4f `p13'
di " 2 and 3" in ye %9. 4f `x23' in ye %9. 4f `p23'
di?--------------------------- "
}
if `g'==4{
local n1 = `2'
local n2 = `3'
local n3 = `4'
local n4 = `5'
local Rs1 = `6'
local Rs2 = `7'
local Rs3 = `8'
local Rs4 = `9'
local H = `10'
local Hc = `11'

local N = `n1'+ `n2' + `n3' + `n4'
local r1 = `Rs1'/ `n1'
local r2 = `Rs2'/ `n2'
local r3 = `Rs3'/ `n3'
local r4 = `Rs4' / `n4'
local C = `H' / `Hc'

local x12 =( `r1'-`r2') 2/( (`N'* (`N'+1) / 12) *( 1/ `n1'+1/ `n2') *`C')
local x13 =( `r1'-`r3') 2/( (`N'* (`N'+1) / 12) *( 1/ `n1'+1/ `n3') *`C')
local x14 =( `r1'-`r4') 2/( (`N'* (`N'+1) / 12) *( 1/ `n1'+1/ `n4') *`C')
local x23 =( `r2'-`r3') 2/( (`N'* (`N'+1) / 12) *( 1/ `n2'+1/ `n3') *`C')
local x24 =( `r2'-`r4') 2/( (`N'* (`N'+1) / 12) *( 1/ `n2'+1/ `n4') *`C')
local x34 =( `r3'-`r4') 2/( (`N'* (`N'+1) / 12) *( 1/ `n3'+1/ `n4') *`C')
local p12 = chiprob( 3, `x12')
local p13 = chiprob( 3, `x13')
local p14 = chiprob( 3, `x14')
local p23 = chiprob( 3, `x23')
local p24 = chiprob( 3, `x24')
local p34 = chiprob( 3, `x34')

di new line(1)
di "Nemenyi test of 4 Groups"
di "--------------------------- "
di "Group chi2 P value"
di "--------------------------- "
di " 1 and 2" in ye %9. 4f `x12' in ye %9. 4f `p12'
di " 1 and 3" in ye %9. 4f `x13' in ye %9. 4f `p13'
di " 1 and 4" in ye %9. 4f `x14' in ye %9. 4f `p14'
di " 2 and 3" in ye %9. 4f `x23' in ye %9. 4f `p23'
di " 2 and 4" in ye %9. 4f `x24' in ye %9. 4f `p24'
di " 3 and 4" in ye %9. 4f `x34' in ye %9. 4f `p34'
di "--------------------------- "
}
}
else{
di new line(1)
di "Error ! The number of groups is not equal to 3 or 4."
}
end
二维码

扫码加我 拉你入群

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

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

全部回复
2017-2-24 23:18:12
把数据和你执行的时候用的命令也一起发上来
二维码

扫码加我 拉你入群

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

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

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

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