Stata 如何为每个已识别的子组运行gllamm?

Stata 如何为每个已识别的子组运行gllamm?,stata,Stata,我必须编写一个ado文件来使用gllamm进行子组元分析。尽管我在循环中有gllamm命令,其中每个命令分别针对每个子组运行,但在结果中,gllamm执行中包含的研究数量是数据集中的研究总数,因此它不会针对每个子组单独运行,而是针对每个子组运行相同的gllamm命令。有什么建议我如何解决这个问题 local i=1 while `j'<=`ngroups' { qui count if (newby==`j') if r(N)==0{ di "Subgroup

我必须编写一个ado文件来使用gllamm进行子组元分析。尽管我在循环中有gllamm命令,其中每个命令分别针对每个子组运行,但在结果中,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
}
}

该代码远没有达到自我包含或自我解释的程度。然而,一些可能有帮助的评论似乎是可能的。主要问题是,给定本地宏1,gllamm调用总是相同的。我强调了其他几个问题。这没有错,但是用while来增加是过时的。forvalues是更现代的样式。我明白了,那么我该如何更改它呢?在-gllamm-命令中添加适当的-if-条件。你能更具体一点吗?非常感谢您迄今为止的帮助!如果条件如前所述适用,则可能是相同的,并且可能应该更加严格。代码必须遵循您尝试执行的统计信息,您没有充分解释这些信息,这不是本文的重点。提供准确的代码可能被视为意味着我完全理解您的代码应该做什么,而我确实不理解。
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
    }
}