Announcement

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

  • Destring variable

    Dear all,

    i have a problem. My variable id is str14 and kind of '10984025984167'. As soon as i try to destring this variable with

    Code:

    destring id, replace ignore(`"'"')

    a single numbers like 1 is displayed but not the number in between these ', i. e. 10984025984167.

    And since the id-values (str14) are different for all of the observations, after destringing, the single number shows up more than once.

    So what's wrong here?

    Many thanks,

    Johanna
    Last edited by Johanna Starkl; 10 Oct 2018, 13:21.

  • #2
    If you destring this variable, I think you will be unhappy: There is no numeric data type available in Stata that will hold a 14 digit number without losing digits, which is likely what causes your problems in distinguishing one number from another. Why do you think you need to destring your ID variable?

    Comment


    • #3
      Mike, I don't understand. The following seems to be working just fine with 14-digit numbers.

      Code:
      clear *
      input str16 id
      10984025984165
      10984025984166
      "'10984025984167'"
      "'10984025984168'"
      "'10984025984169'"
      "'10984025984170'"
      end
      list, clean
      destring id, replace ignore(`"'"')
      format id %14.0f
      list, clean
      Results from the final -list- command:
      Code:
      . list, clean
      
                         id  
        1.   10984025984165  
        2.   10984025984166  
        3.   10984025984167  
        4.   10984025984168  
        5.   10984025984169  
        6.   10984025984170
      --
      Bruce Weaver
      Email: [email protected]
      Web: http://sites.google.com/a/lakeheadu.ca/bweaver/
      Version: Stata/MP 18.0 (Windows)

      Comment


      • #4
        Bruce and Johanna, I'm wrong.

        Double precision will give 16 decimal digits, so this destring should be ok.
        I'm just been in the habit of not taking chances by trying to store a long ID as numeric, particularly considering that there's usually not a good reason to do that, so when I saw the long ID I gave my usual advice (Had someone locally with just this problem last week). Now, in this case, it is true that a double would require 8 bytes, and the long string would take 14, so there would be some space saving.

        And, I have to admit I was somewhat guessing at the original description of the problem (since I didn't know what "a single numbers like 1 is displayed but not the number in between these ', i. e. 10984025984167." meant. Perhaps a small sample, using -dataex- per the FAQ, would be a way to display the problem and get an answer.

        Comment


        • #5
          I am with Mike in spirit here. I have to be puzzled on what these data are and why you want to destring them.

          Comment

          Working...
          X