Announcement

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

  • missing() not working on strings

    Recently, the missing() function no longer identifies empty strings for me as it had earlier. Am I the only one? I think I first noticed this a few weeks ago, but unfortunately I didn't write it down. (I updated stata moments ago just in case, but that didn't help.)

    E.g., I have a string variable for social security numbers (without any dashes) called ssn. I can see empty strings in a browse window (as periods). Here are a few commands and stata's responses, copied from the output window:
    . replace ssn = trim(ssn) // just to be safe
    (0 real changes made)

    . count if missing(ssn)
    0

    . count if ssn=="" // and this isn't working either
    0

    . destring(ssn), replace
    ssn: all characters numeric; replaced as long
    (170 missing values generated)

    . count if missing(ssn)
    170
    Of course, this example is easy to work around, because I can destring; that option isn't available for many or most strings.
    Any help would be appreciated!

    Akiva

  • #2
    Originally posted by Akiva Liberman View Post
    I can see empty strings in a browse window (as periods).
    A lone decimal point in a numeric variable's observation is Stata's way of indicating a missing value, but a period (full stop) in an observation of a string variable is not missing. It's a character.

    Any help would be appreciated!
    You can do something like the following.
    Code:
    replace ssn = "" if strtrim(ssn) == "."

    Comment


    • #3
      Thanks very much! That worked. I wonder how those periods got there, but that is for another day.

      Comment

      Working...
      X