Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, is already up and running.

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

st: MATA function modifies global variables

From   George Vega Yon <>
Subject   st: MATA function modifies global variables
Date   Thu, 6 Jun 2013 16:10:42 -0400

Dear Statalisters,

I'm having a weird problem on variables' scope. I have a function that
takes two objects (a real colvector and a matrix) wich, once inside
the function, are transposed. This function returns a matrix (builded
inside of the function of course). The problem is that the function
seems to actually transpose the global objects (not only the copies
within the function), thing that, as far as I know, should not be
happening as I'm not using pointers to the global objects.

My code looks something like this
/* Function definition */
real colvector myfun(real colvector y, real matrix x) {

real matrix z

y = y'
x = x'

... some code lines (no poiter to Y or X)...


Y = runiform(rows(neig),1)
X = (
        0,0 \
        1,0 \
        1,1 \
        0,1 \
        .9,1/2 \
        .2,.5 \

/* Testing */
for(i=1;i<=100;i++) {
        YC = blop_vec(Y,X)


I get the error

myfun:  3203  Y[1,8] found where colvector required
                 <istmt>:     -  function returned error

Thanks in advanced,

George Vega Yon
7 647 2552
*   For searches and help try:

© Copyright 1996–2016 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index