Monday, March 06, 2006

st: macros & expanding names in mata?

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

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

//parameters is a list of the different parameter settings, corresponding to the existing matrices parameters=(10,20\10,30\20,40)

//create submatrices for each of the distance matrices

for (i=1; i<=rows(parameters); i++) { x=parameters[i,1] y=parameters[i,2] sub_x`x'y`y'=x`x'y`y'[|1,1\20,20|] }

The last line is obviously wrong, but it reflects what I can't figure out in mata terms. Basically, I want to create: sub_x10y20=x10y20[|1,1\20,20|] sub_x10y30=x10y30[|1,1\20,20|] sub_x20y40=x20y40[|1,1\20,20|]

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


Links to this post:

Create a Link

<< Home

This page is powered by Blogger. Isn't yours?