Announcement

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

  • changing numeric string to numeric variable where e5 next to a number means 10^5

    I have a string variable of the type show below, where 63e5 represents 6300000. How do I change it 63e5 to its numeric form.

    x
    ------------
    0
    1864071
    NA
    940268.89
    22557529
    0
    63e5
    NA
    37631925
    NA
    8006659.83
    0
    NA
    NA

  • #2
    i figured it out!

    split x, parse("e")
    replace x1 = "." if fob_amnt == "NA"
    destring x1, replace
    destring x2, replace
    gen y = x1*10^x2 if x2 != .
    replace y = x1 if x2 == .

    Comment


    • #3
      Stata understands scientific notation. So, there is only one inescapable detail, to insist on ignoring "NA".

      Code:
      clear 
      input str9 x 
      0
      1864071
      NA
      940268.89
      22557529
      0
      63e5
      NA
      37631925
      NA
      8006659.83
      0
      NA
      NA
      end 
      
      destring x, gen(X) ignore("NA")
      
      list 
      
           +-----------------------+
           |         x           X |
           |-----------------------|
        1. |         0           0 |
        2. |   1864071     1864071 |
        3. |        NA           . |
        4. | 940268.89   940268.89 |
        5. |  22557529    22557529 |
           |-----------------------|
        6. |         0           0 |
        7. |      63e5     6300000 |
        8. |        NA           . |
        9. |  37631925    37631925 |
       10. |        NA           . |
           |-----------------------|
       11. | 8006659.8   8006659.8 |
       12. |         0           0 |
       13. |        NA           . |
       14. |        NA           . |
           +-----------------------+

      Comment

      Working...
      X