Package com.stata.sfi

Class Mata

java.lang.Object
com.stata.sfi.Mata

public final class Mata extends Object
This class provides access to global Mata matrices. All methods are not thread-safe unless otherwise stated.

Example:

	public static int printMataMatrix(String[] args) {
		String name = args[0];
		long numCol = Mata.getMataColTotal(name);
		long numRow = Mata.getMataRowTotal(name);

		if (Mata.isTypeReal(name)) {
			for (long i = 0; i < numRow; i++) {
				for (long j = 0; j < numCol; j++) {
					double value = Mata.getMataRealAt(name, i, j);
					String index = "[" + (i + 1) + ", " + (j + 1) + "]";
					SFIToolkit.displayln(index + " = " + value);
				}
			}
		}
		else {
			String type = Mata.getMataEltype(name);
			SFIToolkit.errorln("Matrix is type " + type + "; real expected");
			return (3250);
		}
		return 0;
	}

From Stata...

. mata

  // matrix must be global for sfi.Mata to access
  mat = (1, 3, 5 \ 5, 6, 4)

. end

. javacall Examples printMataMatrix, jar(examples.jar) args(mat)
[1, 1] = 1.0
[1, 2] = 3.0
[1, 3] = 5.0
[2, 1] = 5.0
[2, 2] = 6.0
[2, 3] = 4.0

  • Method Details

    • getComplexAt

      @Synchronized public static double[] getComplexAt(double[] matrix, int colCount, int row, int col)
      Get an element from a previously returned matrix.
      Parameters:
      matrix - The matrix.
      colCount - The number of columns in the matrix. This value can be obtained from getMataColTotal().
      row - Zero-based row number.
      col - Zero-based column number.
      Returns:
      The element; a double[2] containing the matrix element.
    • getComplexValues

      @Synchronized public static void getComplexValues(double[] complex, Double real, Double imaginary)
      Get the real and imaginary parts from a complex result.
      Parameters:
      complex - A double[2] containing the matrix element.
      real - A Double to hold the real portion of the result.
      imaginary - A Double to hold the imaginary portion of the result.
    • getMataColTotal

      @Synchronized public static long getMataColTotal(String name)
      Get the number of columns in a Mata matrix.
      Parameters:
      name - Name of the Mata matrix.
      Returns:
      The number of columns. Returns -1 if an error occurs.
    • getMataCompAt

      @Synchronized public static double[] getMataCompAt(String name, long row, long col)
      Read a complex Mata matrix element.
      Parameters:
      name - Name of the Mata matrix.
      row - Zero-based row number.
      col - Zero-based column number.
      Returns:
      A double[2] containing the matrix element. Returns null if an error occurs.
    • getMataEltype

      @Synchronized public static String getMataEltype(String name)
      Get the type of a Mata object.
      Parameters:
      name - Name of the Mata matrix (not function).
      Returns:
      The eltype in String form of the Mata object. Returns an empty String if an error occurs.
    • getMataRealAt

      @Synchronized public static double getMataRealAt(String name, long row, long col)
      Read a real Mata matrix element.
      Parameters:
      name - Name of the Mata matrix.
      row - Zero-based row number.
      col - Zero-based column number.
      Returns:
      The element. Returns a Stata missing if an error occurs.
    • getMataRowTotal

      @Synchronized public static long getMataRowTotal(String name)
      Get the number of rows in a Mata matrix.
      Parameters:
      name - Name of the Mata matrix.
      Returns:
      The number of rows. Returns -1 if an error occurs.
    • getMataStringAt

      @Synchronized public static String getMataStringAt(String name, long row, long col)
      Read a string Mata matrix element.
      Parameters:
      name - Name of the Mata matrix.
      row - Zero-based row number.
      col - Zero-based column number.
      Returns:
      A String containing the matrix element. Returns an empty String if an error occurs.
    • isTypeComplex

      @Synchronized public static boolean isTypeComplex(String name)
      Determine if the matrix type is complex.
      Parameters:
      name - Name of the Mata matrix.
      Returns:
      True if the matrix type is complex.
    • isTypeReal

      @Synchronized public static boolean isTypeReal(String name)
      Determine if the matrix type is real.
      Parameters:
      name - Name of the Mata matrix.
      Returns:
      True if the matrix type is real.
    • isTypeString

      @Synchronized public static boolean isTypeString(String name)
      Determine if the matrix type is string.
      Parameters:
      name - Name of the Mata matrix.
      Returns:
      True if the matrix type is string.