Package com.stata.sfi
Class ValueLabel
java.lang.Object
com.stata.sfi.ValueLabel
This class provides access to Stata's value labels.
Example:
Obtain and print all value labels in the current dataset...
public static int listLabel(String args[]) {
// get all the value-label names
String[] names = ValueLabel.getNames();
if (names == null || names.length == 0) {
SFIToolkit.errorln("No value labels found.");
return 111;
}
// print the labels for each value label
for (String name : names) {
Map<LabelValue, String> map
= ValueLabel.getValueLabels(name, new TreeMap<LabelValue, String>());
SFIToolkit.displayln("\n" + name + ":");
for (Map.Entry<LabelValue, String> entry : map.entrySet()) {
SFIToolkit.displayln(entry.getKey() + " " + entry.getValue());
}
}
return 0;
}
-
Method Summary
Modifier and TypeMethodDescriptionstatic int
createLabel
(String name) Create a new value-label name.static String
Get the label for a specified value-label value.static String
Deprecated.static String[]
Get the labels for a specified value-label name.static String[]
getNames()
Get the names of all value labels in the current dataset.getValueLabels
(String name) Deprecated.This method is deprecated because it is not compatible with getting labels for extended missing values; usegetValueLabels(String, Map)
instead.static Map<LabelValue,
String> getValueLabels
(String name, Map<LabelValue, String> map) Get the value and label pairings for a specified value-label name.static int[]
Deprecated.This method is deprecated because it is not compatible with getting labels for extended missing values; usegetValueLabels(String, Map)
instead.static String
getVarValueLabel
(int index) Get the value-label name associated with a variable.static int
removeLabel
(String name) Remove a value-label name.static int
removeLabelValue
(String name, int value) Remove a value-label value from the specified value-label name.static int
removeLabelValue
(String name, Missing.Extended missingValue) Remove a value-label value from the specified value-label name.static int
removeVarValueLabel
(int index) Remove a value-label name from a variable.static int
setLabelValue
(String name, int value, String label) Set a value and label for a value-label name.static int
setLabelValue
(String name, Missing.Extended missingValue, String label) Set a value and label for a value-label name.static int
setVarValueLabel
(int index, String labelName) Set the value label for a variable.
-
Method Details
-
createLabel
Create a new value-label name.- Parameters:
name
- The new name.- Returns:
- Return code from Stata; 0 if successful.
-
getLabel
Get the label for a specified value-label value. Generally,getValueLabels(String, Map)
should be used instead to get value-label pairings.- Parameters:
name
- The name of the value label.value
- The value to look up.- Returns:
- The label for the specified value-label value. Returns null if an error occurs.
-
getLabel
Deprecated.This method is deprecated because it is not compatible with getting labels for extended missing values; usegetLabel(String, double)
instead.Get the label for a specified value-label value.- Parameters:
name
- The name of the value label.value
- The value to look up.- Returns:
- The label for the specified value-label value. Returns null if an error occurs.
-
getLabels
Get the labels for a specified value-label name. Generally,getValueLabels(String, Map)
should be used instead to get value-label pairings.- Parameters:
name
- The name of the value label.- Returns:
- An array of the labels for the specified value-label name. Returns null if an error occurs.
-
getNames
Get the names of all value labels in the current dataset.- Returns:
- An array of value-label names.
-
getValueLabels
Deprecated.This method is deprecated because it is not compatible with getting labels for extended missing values; usegetValueLabels(String, Map)
instead.Get the values and labels for a specified value-label name.- Parameters:
name
- The name of the value label.- Returns:
- A
Map
containing the values and label pairings for the specified value-label name.
-
getValueLabels
@Synchronized public static Map<LabelValue,String> getValueLabels(String name, Map<LabelValue, String> map) Get the value and label pairings for a specified value-label name.- Parameters:
name
- The name of the value label.map
- The map where the value and label pairings will be stored.- Returns:
- The reference to the original
Map
that was passed as a parameter. - API Note:
- Different
Map
implementing classes have different behavioral properties, so choose theMap
implementation that best meets your needs; seeHashMap
,TreeMap
,Hashtable
,SortedMap
-
getValues
Deprecated.This method is deprecated because it is not compatible with getting labels for extended missing values; usegetValueLabels(String, Map)
instead.Get the values associated with a single value-label name.- Parameters:
name
- The name of the value label.- Returns:
- An array of the values for the specified value-label name. Returns null if an error occurs.
-
getVarValueLabel
Get the value-label name associated with a variable. -
removeLabel
Remove a value-label name.- Parameters:
name
- The name of the value label to remove.- Returns:
- Return code from Stata; 0 if successful.
-
removeLabelValue
Remove a value-label value from the specified value-label name.- Parameters:
name
- The name of the value label.missingValue
- The missing value.- Returns:
- Return code from Stata; 0 if successful.
-
removeLabelValue
Remove a value-label value from the specified value-label name.- Parameters:
name
- The name of the value label.value
- The value to remove.- Returns:
- Return code from Stata; 0 if successful.
-
removeVarValueLabel
Remove a value-label name from a variable.- Parameters:
index
- Index of the variable.- Returns:
- Return code from Stata; 0 if successful.
-
setLabelValue
Set a value and label for a value-label name.- Parameters:
name
- The name of the value label.value
- The value.label
- The label.- Returns:
- Return code from Stata; 0 if successful.
-
setLabelValue
@Synchronized public static int setLabelValue(String name, Missing.Extended missingValue, String label) Set a value and label for a value-label name.- Parameters:
name
- The name of the value label.missingValue
- The missing value.label
- The label.- Returns:
- Return code from Stata; 0 if successful.
-
setVarValueLabel
Set the value label for a variable.- Parameters:
index
- Index of the variable.labelName
- The value-label name.- Returns:
- Return code from Stata; 0 if successful.
-
getLabel(String, double)
instead.