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 <>
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 Baum, Boston College Economics
An Introduction to Modern Econometrics Using Stata:

* For searches and help try:

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