Announcement

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

  • Id variable stored in double format

    Hello Stata members,

    I am analysing dataset in which pid is stored in double format. Since I want to merge different datasets (using pid) to create a single dataset, I need to know the "real numbers" in pid. I used recast command but it is of no help. Using "force" option also did not help as it convert values of pid into missing.

    pid looks like below:

    list pid in 1/10


    pid

    1. 1.0e+00
    2. 2.0e+00
    3. 1.0e+00
    4. 1.0e+00
    5. 1.0e+00
    6. 1.0e+00
    7. 2.0e+00
    8. 2.0e+00
    9. 1.0e+00
    10. 1.0e+00

    Can anyone help please?

    Many thanks

  • #2
    I suggest to use - tostring - command.

    This FAQ may be helpful to you.
    Best regards,

    Marcos

    Comment


    • #3
      Thanks Marcos. I will try and let you know.

      Comment


      • #4
        Dear Marco

        Unfortunately, "tosring" command does not uniquely identify the pid values.
        I did: tostring pid, gen(ids) format("%2.0f") and it generated the following. It just picked the first digit of pid value.

        list pid pids in 1/10


        pid pids

        1. 1.0e+00 1
        2. 2.0e+00 2
        3. 1.0e+00 1
        4. 1.0e+00 1
        5. 1.0e+00 1

        6. 1.0e+00 1
        7. 2.0e+00 2
        8. 2.0e+00 2
        9. 1.0e+00 1
        10. 1.0e+00 1

        Many thanks.

        Comment


        • #5
          Please try with - format("%17.0f") - instead.
          Best regards,

          Marcos

          Comment


          • #6
            Thank you Marcos. Yes, I did with it but unfortunately it did not change the results.

            Comment


            • #7
              Your sample values are just 1 and 2.

              Code:
              . clear
              
              . input pid
              
                         pid
                1. 1e0
                2. 2e0
                3. end
              
              . list
              
                   +-----+
                   | pid |
                   |-----|
                1. |   1 |
                2. |   2 |
                   +-----+
              
              . format pid %2.1e
              
              . list
              
                   +---------+
                   |     pid |
                   |---------|
                1. | 1.0e+00 |
                2. | 2.0e+00 |
                   +---------+
              Please show us the results of

              Code:
              describe pid 
              summarize pid

              Comment


              • #8
                Dear Nick

                Many thanks for providing me with the the codes. I will try and update you.



                Comment


                • #9
                  Dear Nick (and Marcos),

                  Yes, you are correct my values in pid (originally were) are 1 and 2 that is why string command was returning the values 1 and 2.
                  I have discovered that there has been error the way pid was generated.

                  Many thanks for your instant responses. Highly appreciated and very grateful.

                  Comment

                  Working...
                  X