Announcement

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

  • Suspected bug in label command

    Value labels are dictionaries attached to categorical variables that explain the meaning of the codes. The help and manual for Stata illustrate a few typical uses, though do not lay out any requirements for the labels. Specifically it is not explicitly ruled out (or I didn't find it) that the value label can be blank (empty string). This is not a very useful label, I know, but technically it is possible. But it is possible not in all versions of Stata.

    [ 1 ] The following illustrates the differences in behavior of Stata 9.2 and 10.0:

    Code:
    . label define mylabel 1 ""
    invalid attempt to modify label
    r(180);
    The following illustrates the behavior of Stata 11.0, 12.0 and 13.0:
    Code:
    . label define mylabel 1 ""
    
    . label list
    mylabel:
               1


    [ 2 ] Interestingly enough, defining the same missing value cancels it:

    Code:
    . label define mylabel 1 ""
    . label list mylabel
    mylabel:
               1
    . label define mylabel 1 "", modify
    . label list mylabel
    mylabel:


    [ 3 ] Furthermore, adding the version 9.2 statement does not change their behavior. Even under version control they allow an empty value label to be defined.

    [ 4 ] Given the possibility to define a numeric value label, Stata lacks the API to check whether such label is defined. By that I mean that I couldn't find any Stata or Mata command or function that would allow me to distinguish between labelled and unlabelled values in the following (although I can detect this situation programmatically):

    Code:
    sysuse auto, clear
    label define mylabel 1 "1"
    label values rep78 mylabel
    display `"`: label mylabel 1'"'
    display `"`: label mylabel 2'"'
    label list mylabel
    Code:
    . sysuse auto, clear
    (1978 Automobile Data)
    .
    . label define mylabel 1 "1"
    .
    . label values rep78 mylabel
    .
    . display `"`: label mylabel 1'"'
    1
    .
    . display `"`: label mylabel 2'"'
    2
    .
    . label list mylabel
    mylabel:
               1 1



    Now my questions:

    Q1: I can live with #1 above, but will e.g. Stata 9 be ok to find a blank value label in the file ? (It opens the file without complaints, but things can go wrong later)
    Q2: Is #2 an intended behavior? And importantly, will it propagate to future versions?
    Q3: Is #3 a bug? will it be fixed? is it already fixed?
    Q4: Is there an immediate solution for #4? I have two rather ugly solutions: parsing the log of the label list and bruteforcing all integers, both of which look daunting.
    Q5: When translating foreign files into Stata format, should such labels (empty and numeric) be dropped? What does the community think?
    Q6: Similarly, when exporting data from Stata to foreign formats, should such labels be exported? Will they cause unpredictable confusion in other systems? What is your experience?

    Thank you, Sergiy Radyakin



  • #2
    I believe that Q4 can be addressed with labellacking (from SSC).

    Comment


    • #3
      Just some thoughts ...

      Q3: Is #3 a bug? will it be fixed? is it already fixed?
      I can only guess, of course, but it seems like the behavior of Stata releases (prior to) 9 to 10 was regarded a bug later that then has been fixed. This would explain why version control does not change the behavior (it does not reinstate bugs). One could further speculate on Q1 that version 9 was set up to accept empty labels but the label command would not support it.

      I have to add to #2, that I realized differences in Mata and Stata regarding empty labels. Consider

      Code:
      clear
      la de foo 1 ""
      la li
      la de foo 1 "" ,modify
      la li
      
      clear
      m : st_vlmodify("foo", 1, "")
      la li
      m : st_vlmodify("foo", 1, "")
      la li
      which gives

      Code:
      . clear
      
      . la de foo 1 ""
      
      . la li
      foo:
                 1
      
      . la de foo 1 "" ,modify
      
      . la li
      foo:
      
      .
      . clear
      
      . m : st_vlmodify("foo", 1, "")
      
      . la li
      
      . m : st_vlmodify("foo", 1, "")
      
      . la li
      
      .
      meaning that it is not possible to define empty labels in Mata. However I guess this is somewhat in line with the function's name st_vlmodify() that I understand as "if there is an (empty or not) label, remove it". This would also somehow apply to the Stata example where you can set up an empty label, but requesting an existing (empty or not) label to be changed to empty string removes it - just as with label variable.

      Mata also allows you to label system missing values, by the way, although they do not show up in tabulate (etc.). I have reported this to tech support some time ago. Try

      Code:
      clear
      m : st_vlmodify("foo", ., "sysmiss")
      la li

      Q4: Is there an immediate solution for #4? I have two rather ugly solutions: parsing the log of the label list and bruteforcing all integers, both of which look daunting.
      Try the strict option of extended function label as in

      Code:
      sysuse auto, clear
      label define mylabel 1 "1"
      label values rep78 mylabel
      display `"`: label mylabel 1 ,strict'"'
      display `"`: label mylabel 2 ,strict'"'
      label list mylabel
      Edit: Oh I forgot to mention labelbook with the problems option which will flag integer to null string mappings and return the value label names in r(). Also integer to integer mappings are flagged.

      I cannot comment on Q5 and Q6 as I have not tried this.

      Best
      Daniel
      Last edited by daniel klein; 18 Jul 2014, 12:31.

      Comment


      • #4
        [2] above is documented; in the help file

        You can even use the modify option to eliminate existing labels. To do this, you map the numeric
        code to a null string, that is, "":
        . label define yesno 2 "", modify
        . label list yesno
        yesno:
        0 no

        1 yes

        Comment

        Working...
        X