Announcement

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

  • Shortening id numbers

    Dear Stata list,

    I have an 18 digit household id number "010101088801601002". I want to shorten it to a 14 digit number "01010101601002" by removing the middle number "8880". How could I do it in Stata? I have been trying with the 'substr' command, but couldn't figure out it yet. Any help? Thank you.

  • #2
    if the length of the id and the position of the unwanted substring is fixed you can do,
    Code:
    replace id = substr(id,1,7) + substr(id,12,18)

    Comment


    • #3
      Thanks so much Øyvind Snilsberg. It works well. I have another question: Why do Stata give me different results while I am running the same do-file using the same data on the same PC repeatedly.? Is there a mechanism I can detect this problem? Your usual support is appreciated.

      Comment


      • #4
        #3 is rather general. One rather general answer is whether anything depends on sorting the dataset, as in some cases that may affect the results you get. I would start a new thread with more information (e.g. examples of what is different).

        Comment


        • #5
          Dear Nick,

          Thanks for the feedback. Yes, I use "sort household_id" in each of the sections. Is there anything specific that I need to share here?

          Comment


          • #6
            Try adding the option
            Code:
            , stable

            Comment

            Working...
            X