[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Automatically generating variable names in mata

From   L B <>
Subject   st: Automatically generating variable names in mata
Date   Fri, 24 Apr 2009 11:38:28 -0700

I'm new to mata so I apologize if this is an obvious question. I have
a set of locals (although they could also be scalars I guess) I need
to pass on to mata. They're a lot, and so instead of typing out line
by line, say


I want to do something that will create all the mata variables using a
list of which locals to bring into mata, and also to dynamically
create the variable names to match the local names, i.e. I want to
create a mata variable called "hairchar" with the contents of the
local "hairchar". This is typically something you'd do with macros in
Stata so I'm not sure how to do this in Mata. I want to do something
local characteristics hairchar weightchar heightchar ...


for (i=1; 1=cols(charvector), i++) {
    `charvector[i]' = st_local(charvector[i])

In mata I use each of these at separate points in my code so I'd
rather keep each as a separate variable with a distinct name instead
of setting them up as variables in stata, passing them to mata as a
one row vector containing all the locals, eg.  charvector = [hairchar
weightchar heightchar etc] and then having to remember that when I
want heightchar I should use charvector[3] and when I want
manicurechar I should use charvectr[17]

 Someone asked a similar question like this in the past
( the
solution proposed doesn't apply to this example.

Any ideas would be much appreciated!

*   For searches and help try:

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