Announcement

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

  • destring numbers in scientific notation

    Dear community,

    I was inattentive when pasting data into a new stata-file and now the following problem presents itself: I have a unique numeric identifier with verly large number such that stata abbreviated it to scientific notation e.g. 1.7876423e+11. In the new file this numeric identifier appears as string and contains commas (",") instead of dots. I have now trired to destring this varlist unsuccessfully.

    Is there someone who has encountered a similar problem before and could help me out?

    Kind regards,

    Marie

  • #2
    You can do this, but the bad news is that you should really go back and import those numbers again and properly, as otherwise you may well have lost some digits.

    Code:
    . clear
    
    . set obs 1
    number of observations (_N) was 0, now 1
    
    .  gen whatever = "1.7876423e+11"
    
    . split whatever , parse(e) destring
    variables born as string:
    whatever1  whatever2
    whatever1: all characters numeric; replaced as double
    whatever2: all characters numeric; replaced as byte
    
    .  gen double wanted = whatever1 * (10^whatever2)
    
    . format wanted %14.0f
    
    . l
    
         +-----------------------------------------------------+
         |      whatever   whatever1   whatev~2         wanted |
         |-----------------------------------------------------|
      1. | 1.7876423e+11   1.7876423         11   178764230000 |
         +-----------------------------------------------------+

    Comment

    Working...
    X