Package com.stata.sfi

Class 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
    		Map<Integer, String> map;
    		for (int i = 0; i < names.length; i++) {
    			map = ValueLabel.getValueLabels(names[i]);
    			SFIToolkit.displayln("\n" + names[i] + ":");
    			for (Map.Entry<Integer, String> entry : map.entrySet()) {
    				SFIToolkit.displayln(entry.getKey() + " " + entry.getValue());
    			}
    		}
    		return 0;
    	}
    
    
    • Method Detail

      • 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,
                                      int value)
        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. Use this method in conjunction with getValues to obtain two arrays, where array indexes are used to look up each value-label pairing.
        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
        public static Map<Integer,​String> getValueLabels​(String name)
        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.
      • getValues

        @Synchronized
        public static int[] getValues​(String name)
        Get the values associated with a single value-label name. Use this method in conjunction with getLabels to obtain two arrays, where array indexes are used to look up each value-label pairing.
        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,
                                           int value)
        Remove a value-label value.
        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.
      • 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.