com.stata.sfi
Class Data

java.lang.Object
  extended by com.stata.sfi.Data

public final class Data
extends Object

Routines for interacting with a Stata dataset.


Field Summary
static int TYPE_BYTE
           
static int TYPE_DOUBLE
           
static int TYPE_FLOAT
           
static int TYPE_INT
           
static int TYPE_LONG
           
static int TYPE_STR
           
static int TYPE_STRL
           
 
Method Summary
static int addVarByte(String name)
          Add a variable of type byte to the current Stata dataset.
static int addVarDouble(String name)
          Add a variable of type double to the current Stata dataset.
static int addVarFloat(String name)
          Add a variable of type float to the current Stata dataset.
static int addVarInt(String name)
          Add a variable of type int to the current Stata dataset.
static int addVarLong(String name)
          Add a variable of type long to the current Stata dataset.
static int addVarStr(String name, int length)
          Add a variable of type str to the current Stata dataset.
static int addVarStrL(String name)
          Add a variable of type strL to the current Stata dataset.
static int dropVar(int index)
          Drop the variable at the specified variable index.
static int getBestType(double value)
          Get the best numeric data type for the specified value.
static String getFormattedValue(int var, int obs, boolean bValueLabel)
          Read a value from the current Stata dataset applying its display format.
static int getMaxStrLength()
          Get the maximum length of a Stata string (str) variable.
static int getMaxVars()
          Get the maximum number of variables Stata currently allows.
static double getMissingValue()
          Get a Stata missing value.
static double getNum(int var, int obs)
          Read a numeric value from the current Stata dataset.
static int getObsCount()
          Get the number of observations in the current Stata dataset.
static int getParsedIn1()
          Get the first in a range of observations if javacall was called with the in qualifier.
static int getParsedIn2()
          Get the last in a range of observations if javacall was called with the in qualifier.
static int getParsedVarCount()
          Get the number of variables specified when javacall was called.
static Double getRealOfString(String s)
          Get the double representation of a String using Stata's real() function.
static String getStr(int var, int obs)
          Read a string value from the current Stata dataset.
static int getVarCount()
          Get the number of variables in the current Stata dataset.
static String getVarFormat(int index)
          Get the format for a Stata variable.
static int getVarIndex(String varname)
          Look up the variable index for the specified name in the current Stata dataset.
static String getVarLabel(int index)
          Get the label for a Stata variable.
static String getVarName(int index)
          Get the variable name at a given variable index.
static boolean isParsedIfTrue(int obs)
          Determine if the observation is true given an if condition specified with javacall.
static boolean isValueMissing(double value)
          Test if a value is a Stata missing.
static boolean isVarlistSpecified()
          Determine if a varlist was specified with javacall.
static boolean isVarTypeStr(int index)
          Test if a variable is of type str.
static boolean isVarTypeString(int index)
          Test if a variable is string or numeric.
static boolean isVarTypeStrL(int index)
          Test if a variable is of type strL.
static String makeVarName(String s, boolean retainCase)
          Attempt to form a valid variable name from a string.
static int mapParsedVarIndex(int index)
          Map the variable index from the parsed varlist.
static int renameVar(int index, String newname)
          Rename a Stata variable.
static int setObsCount(int obs)
          Set the number of observations in the current Stata dataset.
static int setVarFormat(int index, String format)
          Set the format for a Stata variable.
static int setVarLabel(int index, String label)
          Set the label for a Stata variable.
static int storeNum(int var, int obs, double value)
          Store a numeric value in the current Stata dataset.
static int storeStr(int var, int obs, String value)
          Store a string value in the current Stata dataset.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TYPE_BYTE

public static final int TYPE_BYTE
See Also:
Constant Field Values

TYPE_INT

public static final int TYPE_INT
See Also:
Constant Field Values

TYPE_LONG

public static final int TYPE_LONG
See Also:
Constant Field Values

TYPE_FLOAT

public static final int TYPE_FLOAT
See Also:
Constant Field Values

TYPE_DOUBLE

public static final int TYPE_DOUBLE
See Also:
Constant Field Values

TYPE_STR

public static final int TYPE_STR
See Also:
Constant Field Values

TYPE_STRL

public static final int TYPE_STRL
See Also:
Constant Field Values
Method Detail

getNum

public static double getNum(int var,
                            int obs)
Read a numeric value from the current Stata dataset.

Parameters:
var - Variable to access.
obs - Observation to access.
Returns:
The value.

getStr

public static String getStr(int var,
                            int obs)
Read a string value from the current Stata dataset.

Parameters:
var - Variable to access.
obs - Observation to access.
Returns:
The String. Returns null if an error occurs.

getFormattedValue

public static String getFormattedValue(int var,
                                       int obs,
                                       boolean bValueLabel)
Read a value from the current Stata dataset applying its display format.

Parameters:
var - Variable to access.
obs - Observation to access.
Returns:
The formated value as a String.

storeNum

public static int storeNum(int var,
                           int obs,
                           double value)
Store a numeric value in the current Stata dataset.

Parameters:
var - Variable to access.
obs - Observation to access.
value - Value to store.
Returns:
Return code from Stata; 0 if successful.

storeStr

public static int storeStr(int var,
                           int obs,
                           String value)
Store a string value in the current Stata dataset.

Parameters:
var - Variable to access.
obs - Observation to access.
value - Value to store.
Returns:
Return code from Stata; 0 if successful.

getVarCount

public static int getVarCount()
Get the number of variables in the current Stata dataset.

Returns:
Return the number of variables.

getObsCount

public static int getObsCount()
Get the number of observations in the current Stata dataset.

Returns:
Returns the number of observations.

setObsCount

public static int setObsCount(int obs)
Set the number of observations in the current Stata dataset.

Parameters:
obs - The number of observations to set.
Returns:
Return code from Stata; 0 if successful.

getBestType

public static int getBestType(double value)
Get the best numeric data type for the specified value.

Parameters:
value - The value to test.
Returns:
The field value representing the data type and may be TYPE_BYTE, TYPE_INT, TYPE_LONG, TYPE_FLOAT, or TYPE_DOUBLE.

addVarDouble

public static int addVarDouble(String name)
Add a variable of type double to the current Stata dataset.

Parameters:
name - Name of the variable to be created.
Returns:
Return code from Stata; 0 if successful.

addVarFloat

public static int addVarFloat(String name)
Add a variable of type float to the current Stata dataset.

Parameters:
name - Name of the variable to be created.
Returns:
Return code from Stata; 0 if successful.

addVarLong

public static int addVarLong(String name)
Add a variable of type long to the current Stata dataset.

Parameters:
name - Name of the variable to be created.
Returns:
Return code from Stata; 0 if successful.

addVarInt

public static int addVarInt(String name)
Add a variable of type int to the current Stata dataset.

Parameters:
name - Name of the variable to be created.
Returns:
Return code from Stata; 0 if successful.

addVarByte

public static int addVarByte(String name)
Add a variable of type byte to the current Stata dataset.

Parameters:
name - Name of the variable to be created.
Returns:
Return code from Stata; 0 if successful.

addVarStr

public static int addVarStr(String name,
                            int length)
Add a variable of type str to the current Stata dataset.

Parameters:
name - Name of the variable to be created.
length - Initial size of the variable. If the length is greater than getMaxStrLength then a variable of type strL will be created.
Returns:
Return code from Stata; 0 if successful.

addVarStrL

public static int addVarStrL(String name)
Add a variable of type strL to the current Stata dataset.

Parameters:
name - Name of the variable to be created.
Returns:
Return code from Stata; 0 if successful.

getVarIndex

public static int getVarIndex(String varname)
Look up the variable index for the specified name in the current Stata dataset.

Parameters:
varname - Name of the variable.
Returns:
The variable index.

getVarName

public static String getVarName(int index)
Get the variable name at a given variable index.

Parameters:
index - Index of the variable to lookup.
Returns:
Returns the Name of the Stata variable.

renameVar

public static int renameVar(int index,
                            String newname)
Rename a Stata variable.

Parameters:
index - Index of the variable to rename.
newname - New variable name.
Returns:
Return code from Stata; 0 if successful.

getVarLabel

public static String getVarLabel(int index)
Get the label for a Stata variable.

Parameters:
index - Index of the variable to lookup.
Returns:
Returns the variable's label.

setVarLabel

public static int setVarLabel(int index,
                              String label)
Set the label for a Stata variable.

Parameters:
index - Index of the variable to label.
label - New label.
Returns:
Return code from Stata; 0 if successful.

getVarFormat

public static String getVarFormat(int index)
Get the format for a Stata variable.

Parameters:
index - Index of the variable to lookup.
Returns:
Returns the variable's format.

setVarFormat

public static int setVarFormat(int index,
                               String format)
Set the format for a Stata variable.

Parameters:
index - Index of the variable to format.
format - New format.
Returns:
Return code from Stata; 0 if successful.

dropVar

public static int dropVar(int index)
Drop the variable at the specified variable index.

Parameters:
index - Variable to drop.
Returns:
Return code from Stata; 0 if successful.

makeVarName

public static String makeVarName(String s,
                                 boolean retainCase)
Attempt to form a valid variable name from a string.

Parameters:
s - Source string.
retainCase - If set, the case will not be converted to lowercase.
Returns:
The new variable name. Returns null if a valid name was not created.

getMaxStrLength

public static int getMaxStrLength()
Get the maximum length of a Stata string (str) variable.

Returns:
Return the maximum length.

getMaxVars

public static int getMaxVars()
Get the maximum number of variables Stata currently allows.

Returns:
Maximum number of variables.

isVarTypeString

public static boolean isVarTypeString(int index)
Test if a variable is string or numeric.

Parameters:
index - The index of the variable to test.
Returns:
Returns true if the variable is a string variable of either type str or strL.

isVarTypeStr

public static boolean isVarTypeStr(int index)
Test if a variable is of type str.

Parameters:
index - The index of the variable to test.
Returns:
Returns true if the variable is of type str.

isVarTypeStrL

public static boolean isVarTypeStrL(int index)
Test if a variable is of type strL.

Parameters:
index - The index of the variable to test.
Returns:
Returns true if the variable is of type strL.

isValueMissing

public static boolean isValueMissing(double value)
Test if a value is a Stata missing.

Parameters:
value - The value to test.
Returns:
Returns true if the value is a Stata missing.

getMissingValue

public static double getMissingValue()
Get a Stata missing value.

Returns:
Returns the value of a Stata missing.

getRealOfString

public static Double getRealOfString(String s)
Get the double representation of a String using Stata's real() function.

Parameters:
s - The string to convert.
Returns:
Returns the numeric value. Returns null if an error occurs.

getParsedIn1

public static int getParsedIn1()
Get the first in a range of observations if javacall was called with the in qualifier. If in was not specified then the range will reflect the entire dataset.

Returns:
Returns the first observations number.

getParsedIn2

public static int getParsedIn2()
Get the last in a range of observations if javacall was called with the in qualifier. If in was not specified then the range will reflect the entire dataset.

Returns:
Returns the last observations number.

isVarlistSpecified

public static boolean isVarlistSpecified()
Determine if a varlist was specified with javacall.

Returns:
Return true if javacall was passed a varlist.

getParsedVarCount

public static int getParsedVarCount()
Get the number of variables specified when javacall was called. If a varlist was not specified then all of the variables are implied.

Returns:
Return the number of variables.

mapParsedVarIndex

public static int mapParsedVarIndex(int index)
Map the variable index from the parsed varlist. For example, if javacall is called with three variables, you would loop over 1, 2, and 3. For each iteration you would use this method to translate 1, 2, and 3 to the correct variable index within the dataset.

Parameters:
index - Parsed variable index.
Returns:
The actual variable index in the dataset.

isParsedIfTrue

public static boolean isParsedIfTrue(int obs)
Determine if the observation is true given an if condition specified with javacall. In other words, for the observation, is the if condition true or false.

Returns:
Returns true when the if condition is true for the specified observation.