Announcement

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

  • Converting numeric variable to string using tostring

    Hi Family,
    I have a data set with one variable contained float format(continues variable), I have learn a new command in Stata called tostring to convert from numeric to string.
    When I type the command I found this error

    tostring mydata,replace
    bmi cannot be converted reversibly; no replace

    .
    I attached the data set.


    input float mydata
    12.9
    33.4
    50.2
    19.7
    23.1
    65.8
    76.3
    70.4
    60.1
    53.5
    48.1
    end

    I have go through the help tostring but it is still not clear.

    I will appreciate any help.

    Thank you

  • #2
    Try something like this.
    Code:
    tostring mydata, replace format("%4.1f") force
    Also, if you input these values as a double-precision variable, then
    Code:
    tostring mydata, replace
    will proceed without a hitch.

    Comment


    • #3
      Why would you want to apply tostring there?

      Comment


      • #4
        Originally posted by Nick Cox View Post
        Why would you want to apply tostring there?
        I understood it as trying to learn a new command: "I have [to] learn a new command in Stata called tostring . . ."

        And so the dataset is just an example chosen arbitrarily?

        Comment


        • #5
          Disclosure of interest: I first wrote tostring although it was folded into official Stata a while back, within the life of Stata 8.

          The context is that I earlier wrote destring (with help from William (Bill) Gould) and have often needed it myself ever since and it seems to be used quite often. Bill mentioned to me, either then or at some other time, that if an operation and its inverse or reverse both make sense then software should provide both, regardless of the relative demand for each. It's a good principle and I wrote a tostring privately as an exercise. Then StataCorp got in touch saying that users were asking for the reverse command and had I written one, and in due course that became official too.

          I hope that explains my curiosity, mixed with a degree of paternal interest.

          Comment


          • #6
            Waoo! Mr. Joseph


            I am most grateful for your support. I have being offline for sometime now.
            It has worked. sorry for the late feed back.

            To Mr. Nick, thank you also for asking, that is exactly my intention as explain by Mr Joseph.
            I was soo curious to learn the tostring and see how it work.

            Thank you all for your support once gain.

            Comment

            Working...
            X