我想创建一个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
来做,但是因为我有很多论据,所以调用我的程序太乱了。
答案 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)