Announcement

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

  • May not label .

    This post probably targeted at Stata developers, but is posted here for public discussion as well:


    The following produces an error 198 "May not label ."
    Code:
    label define dottest . "is a dot"

    However the following works:
    Code:
    label define dottest 2147483621 "is a dot" 0 "is zero"
    set obs 2
    generate long x=2147483621
    replace x=0 in 2
    label values x dottest
    Produces the following label dictionary:

    Code:
    dottest:
               0 is zero
               . is a dot
    Produces dataset:
    Code:
         +---------+
         |       x |
         |---------|
      1. |       . |
      2. | is zero |
         +---------+
    The value label for a dot is present in the dictionary, and is saved with the data into a file. But it is not displayed.

    Interestingly if I attempt

    Code:
    label define dottest 2147483622 "dot A"
    it produces an error, so that one has to:
    Code:
    label define dottest .a "dot A"
    This behavior looks somewhat inconsistent to me.

    1) Shouldn't the value 2147483621 be banned as well? Or
    2) Shouldn't the values 2147483622 and above be accepted and automatically recoded into .a...z?
    3) If the label for a dot gets defined (one way or another), shouldn't it be applied when listing the data?
    4) Will the files containing such a value label continue to be opened by Stata in the future?

    Thank you, Sergiy Radyakin


  • #2
    From help label (in Stata 13.1 for Mac, at least) we first read
    Code:
    Define value label
    
        label define lblname # "label" [# "label" ...] [, add modify replace nofix]
    and then, on the 15th non-blank line following, separated by the definitions of several other label subcommands, none of which include # in the syntax, we read
    Code:
    where # is an integer or an extended missing value (.a, .b, ..., .z).
    Finally, much further down, we read

    label define defines a list of up to 65,536 (1,000 for Small Stata) associations of integers and text called value labels.
    which makes no mention of missing values.

    Comment


    • #3
      Thank you William. That is exactly the point. The documentation implies labels for system missings may not be defined.
      The following code:
      Code:
      label define dottest 2147483621 "is a dot"
      defines a label for a system missing. What are the consequences?

      Comment


      • #4
        I have mentioned this elsewhere, but Mata lets you label system missing values as well - with the same result.

        Code:
        mata : st_vlmodify("dottest", ., "is a dot")
        label list dottest
        In the help file this is, however, kind of documented.

        The only conditions under which the above functions abort with error is when name is malformed or Mata is out of memory. Functions tolerate all other problems.
        Best
        Daniel

        Comment


        • #5
          Thank you Daniel.

          This seems like a dual bug for me:

          1) the value label for a system missing (dot) (as per documentation) should not be definable, but gets defined via the methods that Daniel and I have shown (see also this earlier thread).
          2) once such a value label is defined, it is applied by Stata incorrectly, as the following code demonstrates:

          Code:
          version 13.0
          clear
          sysuse auto
          keep in 1/6
          
          generate double x=2147483618+_n
          format x %20.0f
          replace x=. in L
          clonevar x2=x
          
          label define x 2147483621 "Value: [2147483621]"
          mata : st_vlmodify("x", .a, "AAAAA")
          mata : st_vlmodify("x", .b, "BBBBB")
          label values x x
          label list x
          
          list x x2
          Produces output:
          Code:
          . label list x
          x:
                     . Value: [2147483621]
                    .a AAAAA
                    .b BBBBB
          
          .
          . list x x2
          
               +----------------------------------+
               |                   x           x2 |
               |----------------------------------|
            1. |          2147483619   2147483619 |
            2. |          2147483620   2147483620 |
            3. | Value: [2147483621]   2147483621 |
            4. |          2147483622   2147483622 |
            5. |          2147483623   2147483623 |
               |----------------------------------|
            6. |                   .            . |
               +----------------------------------+
          Best, Sergiy Radyakin

          Comment

          Working...
          X