如何解决如何为每个已识别的子组运行 gllamm?
我必须编写一个 ado 文件来使用 gllamm
进行亚组荟萃分析。即使我在每个命令分别为每个子组运行的循环中有 glamm 命令,在结果中 gllamm
执行中包含的研究数量是数据集中的研究总数,因此它不为每个子组单独运行,但为每个子组运行相同的 gllamm
命令。有什么建议可以解决这个问题吗?
local i=1
while `j'<=`ngroups' {
qui count if (newby==`j')
if r(N)==0{
di "Subgroup analysis can not be completed"
}
qui sum `1' if newby==`j'
scalar `k'=r(N)
di in ye "The number of studies included in this Meta-analysis is " `k'
qui levelsof `2',local(slev)
foreach i in `slev' {
if `i'<=0 {
di as err "Varlist s should only contain positive values"
exit 125
}
}
eq het: `2'
constraint define 1 `[s1]'`2'=1
gllamm `1',i(id) s(het) nats constraint(1) level(`l') adapt prior(gamma,scale(10000) shape(2))
local j=`j'+1
}
}
解决方法
local i=1
* presumably local j = 1 before this
* presumably local ngroups defined before this
while `j'<=`ngroups' {
qui count if (newby==`j')
if r(N)==0 {
di "Subgroup analysis can not be completed"
* !!! you need to get out of the loop here
}
qui sum `1' if newby==`j'
* summarize,meanonly better style
scalar `k'=r(N)
di in ye "The number of studies included in this meta-analysis is " `k'
qui levelsof `2',local(slev)
* !!! shouldn't this also be for the current group of newby
* !!! why don't you insist here that you only want positive values
!!! you're already using i as a local macro name
foreach i in `slev' {
if `i'<=0 {
di as err "Varlist s should only contain positive values"
exit 125
}
}
eq het: `2'
constraint define 1 `[s1]'`2'=1
* !!! this is the same every time Stata gets to here
* !!! so long as local macro 1 is the same
* !!! you may need to slap -if- conditions on the command
* !!! Stata won't select a subset just because you are inside a loop
gllamm `1',i(id) s(het) nats constraint(1) level(`l') adapt prior(gamma,scale(10000) shape(2))
local j=`j'+1
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。