Package com.stata.sfi

Class Scalar

java.lang.Object
com.stata.sfi.Scalar

public final class Scalar extends Object
This class provides access to Stata scalars.

Examples:

Loading and saving scalars...

	public static int getStringScalar(String[] args) {
		String name = args[0];
		String contents = Scalar.getString(name);
		SFIToolkit.displayln(name + " = " + contents);
		return 0;
	}

	public static int setStringScalar(String[] args) {
		String name = args[0];
		String contents = args[1];
		int rc = Scalar.setString(name, contents);
		return rc;
	}

	public static int getScalar(String[] args) {
		String name = args[0];
		Double contents = Scalar.getValue(name);
		SFIToolkit.displayln(name + " = " + contents);
		return 0;
	}

	public static int setScalar(String[] args) {
		String name = args[0];
		Double value = Double.parseDouble(args[1]);
		int rc = Scalar.setValue(name, value);
		return rc;
	}

  • Field Details

  • Method Details

    • getString

      @Synchronized public static String getString(String name)
      Get the contents of a Stata string scalar.
      Parameters:
      name - Name of the scalar.
      Returns:
      Value of the scalar. Returns null if the scalar is not found or if the scalar is marked as binary.
    • getString

      @Synchronized public static String getString(String name, int type)
      Get the contents of a Stata string scalar.
      Parameters:
      name - Name of the scalar.
      type - Type of the scalar; may be TYPE_AUTOMATIC, TYPE_GLOBAL, or TYPE_CRETURN.
      Returns:
      Value of the scalar. Returns null if the scalar is not found or if the scalar is marked as binary.
    • getValue

      @Synchronized public static Double getValue(String name)
      Get the contents of a Stata scalar.
      Parameters:
      name - Name of the scalar.
      Returns:
      Value of the scalar. Returns null if the scalar is not found.
    • getValue

      @Synchronized public static Double getValue(String name, int type)
      Get the contents of a Stata scalar.
      Parameters:
      name - Name of the scalar.
      type - Type of the scalar; may be TYPE_AUTOMATIC, TYPE_GLOBAL, TYPE_RETURN, TYPE_RRETURN, TYPE_ERETURN, or TYPE_CRETURN.
      Returns:
      Value of the scalar. Returns null if the scalar is not found.
    • setString

      @Synchronized public static int setString(String name, String value)
      Set the contents of a Stata string scalar.
      Parameters:
      name - Name of the scalar.
      value - Value to store in the scalar.
      Returns:
      Return code from Stata; 0 if successful.
    • setString

      @Synchronized public static int setString(String name, String value, int type)
      Set the contents of a Stata string scalar.
      Parameters:
      name - Name of the scalar.
      value - Value to store in the scalar.
      type - Type of the scalar; may be TYPE_AUTOMATIC or TYPE_GLOBAL.
      Returns:
      Return code from Stata; 0 if successful.
    • setValue

      @Synchronized public static int setValue(String name, double val)
      Set the value of a Stata scalar. If necessary, the scalar will be created.
      Parameters:
      name - Name of the scalar.
      val - Value to store in the scalar.
      Returns:
      Return code from Stata; 0 if successful.
    • setValue

      @Synchronized public static int setValue(String name, double value, int type)
      Set the value of a Stata scalar. If necessary, the scalar will be created.
      Parameters:
      name - Name of the scalar.
      value - Value to store in the scalar.
      type - Type of the scalar; may be TYPE_AUTOMATIC, TYPE_GLOBAL, TYPE_RETURN, TYPE_RRETURN, or TYPE_ERETURN.
      Returns:
      Return code from Stata; 0 if successful.
    • setValue

      @Synchronized public static int setValue(String name, double value, int type, int vtype)
      Set the value of a Stata scalar. If necessary, the scalar will be created.
      Parameters:
      name - Name of the scalar.
      value - Value to store in the scalar.
      type - Type of the scalar; may be TYPE_AUTOMATIC, TYPE_GLOBAL, TYPE_RETURN, TYPE_RRETURN, or TYPE_ERETURN.
      vtype - If the scalar is a type of return value, sets whether the return value is VTYPE_VISIBLE, VTYPE_HIDDEN, or VTYPE_HISTORICAL. This parameter is ignored with TYPE_GLOBAL.
      Returns:
      Return code from Stata; 0 if successful.
    • setValue

      @Synchronized public static int setValue(String name, double value, int type, String version)
      Set the value of a Stata scalar. If necessary, the scalar will be created.
      Parameters:
      name - Name of the scalar.
      value - Value to store in the scalar.
      type - Type of the scalar; may be TYPE_GLOBAL, TYPE_RETURN, TYPE_RRETURN, or TYPE_ERETURN.
      version - If the scalar is a type of return value, sets the release number in the form #[#][.[#[#]]] for a return result. This parameter is ignored with TYPE_GLOBAL.
      Returns:
      Return code from Stata; 0 if successful.