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

  • Double to String error: cannot be converted reversibly; no replace

    I am trying to convert a double to a string using tostring; however, I keep getting the following error message: AgeatTimeofDisposition cannot be converted reversibly; no replace. Can someone help resolve this?

    HTML Code:
    tostring AgeatTimeofDisposition, replace

  • #2
    Any resolution depends on seeing what the data look like and understanding why you want this.


    • #3
      I'd suspect that the default numeric format (e.g., %10.0g) is insufficient to hold the type double data in your Age... variable with full precision. There are various ways to remedy this, including using the -force- option of -tostring- (See -help tostring- and look at the force option to understand this better). You also could use the -format- option of -tostring- to use a wider format for the new variable. However, I'd have two side comments: 1) Is there a reason to store an Age variable (presumably of a person) with all the precision of a double in the first place? 2) But perhaps more importantly: You might explain here why you want to make a numeric age variable into a string. I can't offhand think of any reason why that would be helpful --perhaps a deficit of my imagination <grin>--, so perhaps your use of -tostring- is not a good way to accomplish whatever you wanted to do anyway.


      • #4
        Mike Lacy The reason for this conversion is to append two data sets. The first data set has the variable in double, the second in string (in this dataset there are a few instances where there are non-numeric values).


        • #5
          In that case, I'd recommend converting the string version of the variable to numeric, since a non-numeric age is unlikely to be useful. If you're in a situation in which you can't permanently change the file with the string version of age, various solutions exist. My preference would be to load the file with the string variable(s), -destring- it, and save the file to a temp. file before appending. There is a -force- option on -append-, but I would prefer the transparency and control of doing the numeric conversion myself. I'd also want to satisfy myself as to why those numeric variables got saved as string variables, the most likely cause being certain common errors that occur while importing Excel files.