Package com.stata.sfi

Class ValueLabel

java.lang.Object
com.stata.sfi.ValueLabel

public final class ValueLabel extends Object
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 Details

    • createLabel

      @Synchronized public static int createLabel(String name)
      Create a new value-label name.
      Parameters:
      name - The new name.
      Returns:
      Return code from Stata; 0 if successful.
    • getLabel

      @Synchronized public static String getLabel(String name, double value)
      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

      @Synchronized @Deprecated public static String getLabel(String name, int value)
      Deprecated.
      This method is deprecated because it is not compatible with getting labels for extended missing values; use getLabel(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

      @Synchronized public static String[] getLabels(String name)
      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

      @Synchronized public static String[] getNames()
      Get the names of all value labels in the current dataset.
      Returns:
      An array of value-label names.
    • getValueLabels

      @Synchronized @Deprecated public static Map<Integer,String> getValueLabels(String name)
      Deprecated.
      This method is deprecated because it is not compatible with getting labels for extended missing values; use getValueLabels(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 the Map implementation that best meets your needs; see HashMap, TreeMap, Hashtable, SortedMap
    • getValues

      @Synchronized @Deprecated public static int[] getValues(String name)
      Deprecated.
      This method is deprecated because it is not compatible with getting labels for extended missing values; use getValueLabels(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

      @Synchronized public static String getVarValueLabel(int index)
      Get the value-label name associated with a variable.
      Parameters:
      index - Index of the variable.
      Returns:
      The value-label name associated with a variable. Returns an empty String if a value label is not associated with the specified variable. Returns a null String if an error occurs.
    • removeLabel

      @Synchronized public static int removeLabel(String name)
      Remove a value-label name.
      Parameters:
      name - The name of the value label to remove.
      Returns:
      Return code from Stata; 0 if successful.
    • removeLabelValue

      @Synchronized public static int removeLabelValue(String name, Missing.Extended missingValue)
      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

      @Synchronized public static int removeLabelValue(String name, int value)
      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

      @Synchronized public static int removeVarValueLabel(int index)
      Remove a value-label name from a variable.
      Parameters:
      index - Index of the variable.
      Returns:
      Return code from Stata; 0 if successful.
    • setLabelValue

      @Synchronized public static int setLabelValue(String name, int value, String label)
      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

      @Synchronized public static int setVarValueLabel(int index, String labelName)
      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.