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

st: Re: MATA: dynamically generating variable names in MATA

From   Kit Baum <>
Subject   st: Re: MATA: dynamically generating variable names in MATA
Date   Sun, 23 Mar 2008 08:46:34 -0400

What you describe below creates variables equal to constants, which is not a good idea in Stata. If you want to have a set of scalar values taking on specific values, use the scalar command in Stata. You can, as others have suggested, do something similar with matrix elements in Mata (which, like Stata, is not an acronym). You can also use Mata pointers to create a set of temporary variables in Mata.

Kit Baum, Boston College Economics and DIW Berlin
An Introduction to Modern Econometrics Using Stata:

On Mar 23, 2008, at 02:33 , statalist-digest wrote:

Is there anyway of dynamically generating variable names in MATA?

For example, I would like to be able to write something like this:

count = 10
for(x=1; x<=count; x++) {
y = strofreal(x)
hello_`y' = x*10

and is this way generate 10 variables named hello_1, hello_2, ... hello_10.

I know that the STATA local ` ' syntax doesn't work in MATA, but it
would be very very helpful to me to be able to be able to dynamically
generate variables in MATA.

If there isn't anyway of dynamically generating variables in MATA, are
there any work arounds you suggest?
*   For searches and help try:

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