Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Undesirable (?) behavior of -label values- with a non-existent label name

    While debugging the failure of value labels to be assigned to some variables in a long syntax file, I discovered that -label values- does not complain if given a non-existent (likely misspelled) label name. It assigns a value label with no content to the variable, which removes any existing label:
    Code:
    sysuse auto, clear
    gen byte x = runiform() > 0.6
    label values x origi //  non-existing label, truncated/misspelled existing value label
    desc x
    tab x
    //
    tab foreign, label
    label values foreign MyMistake
    tab foreign, label
    I suppose this behavior could be regarded as desirable, as it means that a labeling mistake doesn't break syntax, but it's undesirable in a) failing to help one discover a spelling or other error, and b) allowing one to remove a good label by accident. This is clearly not a big deal, and might even be documented, but perhaps having heard about this will save someone else a similar confusion.

  • #2
    There is probably not a universally valid answer to the question of whether the behavior is desirable or not. I would say it is consistent with Stata's logic that defining and attaching a value label are two separate steps.

    Anyway, the behavior is documented; the very first example in [D] label -- Manipulate labels starts with

    Although describe shows the names of the value labels, those value labels may not exist.

    My elabel (from SSC) is one way of finding such undefined value labels.

    Code:
    . elabel dir , nomemory
    origin
    origi*
    MyMistake*
    
    Note: * indicates value label is not stored in memory

    Comment


    • #3
      Daniel, I predicted in advance to myself that you as our resident label-master would have better knowledge of this than I do. <grin>

      Comment

      Working...
      X