Announcement

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

  • how to Generate 5 digit id

    Dear all
    i had some id like 1 to 2400 and i need to make them all 5 digit ID like id 1 will be 10001, id 5 will be 10005 and 1226 will be 11226, 2120will be 12120
    regards
    Raeed

  • #2

    Code:
    gen newid = id + 10000

    Comment


    • #3
      thanks dear Nick

      Comment


      • #4
        what should i do if i want generate id=(chid+mid)
        if chid=10142, mid=1 id=1014201
        10143 2 1014302
        10145 3 1014503
        10146 10 1014610
        10159 15 1015915
        note that chid and mid is string
        Last edited by Raeedur Rahman; 01 Nov 2016, 00:26.

        Comment


        • #5
          if mid is 1, 2 , 5 , 6 , 9 , 12 , 15 how can i make them two digit number like 01, 02, 05, 09, 12, 15

          Comment


          • #6
            For #5 see discussion at http://www.statalist.org/forums/foru...1362452-format

            After 70 or so posts here you should please be familiar with guidelines and be using dataex (SSC) to give data examples. See FAQ Advice #12.

            For #4 consider this:

            Code:
            clear 
            input str5 chid str2 mid str7 wanted 
            "10143" "2"  "1014302"
            "10145" "3"  "1014503"
            "10146" "10" "1014610"
            "10159" "15" "1015915"
            end 
            
            gen try1 = string(100 * real(chid) + real(mid)) 
            gen try2 = chid + cond(length(mid) == 1, "0" + mid, mid) 
            
            assert wanted == try1
            assert wanted == try2 
            
            list 
            
                 +-------------------------------------------+
                 |  chid   mid    wanted      try1      try2 |
                 |-------------------------------------------|
              1. | 10143     2   1014302   1014302   1014302 |
              2. | 10145     3   1014503   1014503   1014503 |
              3. | 10146    10   1014610   1014610   1014610 |
              4. | 10159    15   1015915   1015915   1015915 |
                 +-------------------------------------------+

            Comment

            Working...
            X