set obs 30
mata
r1=30
c1=5
a=uniform(r1,c1)
d1=J(r1,1,0)
for (i = 1; i <= c1; i++) {
d1=a[.,i]
name = "x" + strofreal(i)
st_store(.,st_addvar("float",name),d1)
}
end
*不用循环
clear all
set ob 30
mata
a=uniform(30,5)
st_store(.,st_addvar("float",("x1","x2","x3","x4","x5")),a)
end
*用循环
clear all
set ob 30
mata
a=uniform(30,5)
for(i=1;i<=5;i++) st_store(.,st_addvar("float","x"+strofreal(i)),a[.,i])
end