Statalist The Stata Listserver

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

st: macros & expanding names in mata?

From   Matissa Hollister <>
Subject   st: macros & expanding names in mata?
Date   Mon, 6 Mar 2006 08:02:09 -0800 (PST)

I'm still trying to figure out how to think in mata
terms after finally getting comfortable in stata.  I
struggle in particular with how to do things in mata
that I find relatively easy to do in stata with
macros.  Right now I'm stumped with the following

I have a set of matrices I created in mata with
distances between pairs of individuals.  The algorithm
I used to calculate the distances varies by two
parameters, x and y, each ranging from 1 to 100.  Each
matrix represents the results under different levels
of these two parameters and the matrix names reflects
these settings (e.g. x10y20 or x20y40).  I now want to
do a series of manipulations and calculations on these
matrices and I'm having difficulties figuring out how
to iterate across the matrix names, in particular how
to proxy for the names.  Here's an example.  The
original distance matrices are already loaded into

//parameters is a list of the different parameter
settings, corresponding to the existing matrices

//create submatrices for each of the distance matrices

for (i=1; i<=rows(parameters); i++) {

The last line is obviously wrong, but it reflects what
I can't figure out in mata terms.  Basically, I want
to create:

Later on I want to do other calculations for each of
the matrices.  I know that pointers are in some ways
the equivalent to macro in mata, although I'm still
trying to wrap my head around them.  It seems like
macros are more flexible in their ability to expand
within strings and variable names.  I know, though,
that some things just have to be done differently
within mata because it's compiled, so perhaps I'm
going at this all wrong.  Any suggestions on how to
accomplish this task within mata would be greatly
appreciated.  I could resort to calling things from
stata so that I can use macros, but it would be kind
of a pain.



Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
*   For searches and help try:

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