将向量作为参数传递给Mata函数

时间:2014-12-11 00:34:46

标签: vector arguments stata

我想创建一个Stata程序,它会接受一些参数并将它们传递给Mata,其中一个参数应该是vector。简化版:

clear
cap prog drop my1
program my1
    version 13
    syntax , it(int) beta(numlist)
    ... maybe to transform numlist to vector somehow?

    mata: mymata(`it',`beta')
end
mata: mata clear
mata:
void mymata(real scalar it,
            real vector beta)
{
            it
            beta
            beta'
}
end
mata: mata mosave mymata(), dir(PERSONAL) replace

my1 , it(1234) beta(1,2,3)

有没有简单的方法将这个numlist变成一个向量并将其传递给mata?我设法用args而不是syntax来做,但是因为我有很多论据,所以调用我的程序太乱了。

1 个答案:

答案 0 :(得分:3)

clear
cap prog drop my1
program my1
    version 13
    syntax , it(int) beta(numlist)
    local beta: subinstr local beta " " ", ", all


    mata: mymata(`it',(`beta'))
end
mata: mata clear
mata:
void mymata(real scalar it,
            real vector beta)
{
            it
            beta
            beta'
}
end

my1 , it(1234) beta(1 2 3)