Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: re: adding variables from Mata


From   Kit Baum <[email protected]>
To   [email protected]
Subject   st: re: adding variables from Mata
Date   Sat, 31 Mar 2007 13:51:39 -0400

Amadou said

> 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.


IMHO easiest way to do this is to create the variables in Stata as missing, create a view matrix in Mata of those variables, and just fill it in. Viewsource hprescott.ado for an example.

Kit


Kit Baum, Boston College Economics
http://ideas.repec.org/e/pba1.html
An Introduction to Modern Econometrics Using Stata:
http://www.stata-press.com/books/imeus.html


*
* 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/




© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index