Amadou ([email protected]) asked me the same thing offlist. My answer was:
The following should work:
for (i=1; i<=cols(Z1); i++) {
printf("i=%g\n",i)
Z1i = Z1[1...,i]
nomx = ("Z1" + strofreal(i))
stata("cap drop " + nomx)
st_addvar("double", nomx)
st_store(.,nomx,Z1i)
}
ben
On 3/31/07, Maarten Buis <[email protected]> wrote:
--- [email protected] wrote:
> My problem is that I need to return some colvector
> matrices in stata as variables to be used later. I
> don't know how to do that:
>
> for (i=1; i<=cols(Z1); i++) {
> printf("i=%g\n",i)
> Z1i = Z1[1...,i]
> nomx = ("Z1i")
> stata("cap drop Z1i")
> // I tried "cap drop Z1`i'", not working
> st_addvar("double",nomx)
> st_store(.,nomx,Z1i)
> }
>
> My matrice Z1 has 3 columns. I want to create Z11
> Z12 Z13 as new variables in my datasets. But in
> Stata I only get Z1i as a variable.
I am no mata expert, all I can tell you is what I found
in the helpfiles:
I don't think it is necessary to loop here:
-help mf_st_addvar- tells me you can create multiple
variables in one go and -help mf_st_store- tells me you
can store a matrix.
I forwarded this answer to the statalist in case there
is a mata expert listening and willing to check or
elaborate my answer.
Hope this helps,
Maarten
-----------------------------------------
Maarten L. Buis
Department of Social Research Methodology
Vrije Universiteit Amsterdam
Boelelaan 1081
1081 HV Amsterdam
The Netherlands
visiting address:
Buitenveldertselaan 3 (Metropolitan), room Z434
+31 20 5986715
http://home.fsw.vu.nl/m.buis/
-----------------------------------------
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/