Announcement

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

  • Identifying specific variable value - trailing blank?

    Hello

    I have a problem with what seems to be a blank in a string.
    The str10 variable is called X and a commonly occurring value is "DVAXX". This value is e.g. observed for observation number 1.
    However, another value of X is also observed. This value is e.g. observed for observation number 2.
    My problem is that I am not able to identify this other value. The codebook command confirms that the type is str6.
    I suspected the value to be "DVAXX " (that is with a trailing blank), but when I type:

    Code:
    display substr(X[2],6,1)==" "
    the result is 0 i.e. false, contrary to what I achieve when typing:

    Code:
    display substr("DVAXX ",6,1)==" "
    Here the result is 1 i.e. true.
    When I type:

    Code:
    display substr(X[2],6,1)
    no symbol is shown in the result window. In other words I am not able to visually discern it from the result I get when typing:

    Code:
    display substr("DVAXX ",6,1)
    Thus my question is: what is the value of X[2] and how do I find out?

    Best regards
    Andreas Jensen
    Last edited by Andreas Jensen; 24 Oct 2017, 06:39.

  • #2
    Stata has just one double quote character, always displayed as upright, so the display above of left-leaning and right-leaning characters is distracting.

    I can't make sense of even a corrected version of your second statement, which isn't even legal:

    Code:
    . display substr("DVAXX ")==" "
    invalid syntax
    r(198);
    charlist from SSC may help in identifying the puzzling characters. It may be char(160).

    Comment


    • #3
      Maybe
      Code:
      assert x[2] == "DVAXX "
      or
      Code:
      display strpos(x[2], " ")

      Comment


      • #4
        Originally posted by Nick Cox View Post
        Stata has just one double quote character, always displayed as upright, so the display above of left-leaning and right-leaning characters is distracting.

        I can't make sense of even a corrected version of your second statement, which isn't even legal:

        Code:
        . display substr("DVAXX ")==" "
        invalid syntax
        r(198);
        charlist from SSC may help in identifying the puzzling characters. It may be char(160).
        I agree that the quoting was distracting. It is now edited. And the second statement is edited to make sense as well.

        Originally posted by Joseph Coveney View Post
        Maybe
        Code:
        assert x[2] == "DVAXX "
        or
        Code:
        display strpos(x[2], " ")
        1) It says 'assertion is false'
        2) I tried that and '0' is returned - meaning that X[2] does not contain the string " ".
        Last edited by Andreas Jensen; 24 Oct 2017, 07:03.

        Comment


        • #5
          It might be ANSI decimal code point 160, as Nick mentioned. If so, then
          Code:
          display strpos(x[2], char(160))
          would show it. Or try charlist as Nick suggested.

          Comment


          • #6
            Originally posted by Joseph Coveney View Post
            It might be ANSI decimal code point 160, as Nick mentioned. If so, then
            Code:
            display strpos(x[2], char(160))
            would show it. Or try charlist as Nick suggested.
            It says zero again. It might be another char(), though? I try to run a loop and see.

            Edit: It worked. Apparently the character was char(13)
            Last edited by Andreas Jensen; 24 Oct 2017, 07:10.

            Comment

            Working...
            X