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

st: Plugin programming, strange behavior

From   "Sergiy Radyakin" <[email protected]>
To   "[email protected]" <[email protected]>
Subject   st: Plugin programming, strange behavior
Date   Mon, 14 Jan 2008 10:54:47 -0500

Dear Stata users,

there is a strange behavior of the SF_mat_store() function called from
a plugin, which makes me suspect a bug in Stata. Both versions 9 and
10 seem to be affected. When writing a value to the matrix from within
a plugin with the above mentioned function, if the matrix is a square
matrix initialized with missings before the plugin is called, then the
value written to element (i,j) will also be written to the element
(j,i), overriding the value which is already there. Such behavior
artificially causes the resulting matrix to be symmetric, even when it
is not.

According to the only available source of information regarding
plugins in Stata ( the function:


stores value v to the element (i,j) of the matrix s.

Here is a trivial example of the code (Delphi):

SF_mat_store(PChar('MATRIX_MEANS'), 1, 2, C);
SF_mat_store(PChar('MATRIX_MEANS'), 2, 1, S);

For a 10x10 MATRIX_MEANS initialized with missings, both elements
(1,2) and (2,1) will have value S. If only the first line of code is
executed, then both elements (1,2) and (2,1) have their value C.

At first I thought that the declaration of the SF_mat_store() function
within Delphi were incorrect, but the problem described above
disappears, when the matrix is non-symmetric before the call. So to
avoid the problem, I have found two ways so far:

1. make the matrix to be rectangular (non-square) by adding a column,
and stripping it after a call to the plugin.

2. Initialize a value in the matrix off the main diagonal from within
Stata, (e.g. writing 1 to (1,2)) before calling the plugin, and making
sure that the plugin overwrites ALL values in the matrix with either a
valid number or a missing value.

The fact that 1 and 2 both work and cause results to be different from
the default behavior of plugin call with an empty matrix (with the
_same_ compiled plugin file) makes me think that there is a bug in the
implementation of the plugin interface in Stata 9 and 10.

Or is this an intended behavior?

It would be great if anyone working with plugins could confirm the
problem, or explain how to avoid the problem. Also, is there any way
to assign rownames() / colnames() of a matrix from within a plugin?
Add a variable from within a plugin? Read variable characteristics
from within a plugin?

Thank you,
   Sergiy Radyakin
   Consultant, DECRG, The World Bank
*   For searches and help try:

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