Announcement

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

  • Selecting observations beginning with a specific numeric value

    Hello,

    I'm a new Stata user and struggling to match survey data on village level with data for households belonging to those villages. Each village is identified by an 8-digit code and each household is identified by a 12-digit code where the first 8 digits are the same as the village they belong to. E.g. village ID is 88888888 and household IDs 888888881234 888888881235 and so on. Is there any command which would pick out observations beginning with the 8 digits? Also, it there any way to do this automatically for all the villages (there is about 200 of them)?

    Thank you very much for any advice

  • #2
    Are your identifiers string or numeric?

    Comment


    • #3
      String, but I also encoded them to use with another command so can use either

      Comment


      • #4
        encoded identifiers rarely help much.

        Some technique:

        Code:
        clear
        input str11 whatever 
        8888888842
        88888888123
        88888888666
        123456 
        end 
         
        list if substr(whatever, 1, 8) == "88888888"
        
             +-------------+
             |    whatever |
             |-------------|
          1. |  8888888842 |
          2. | 88888888123 |
          3. | 88888888666 |
             +-------------+
        
        list if substr(whatever, 1, 8) == 8*"8"
        
             +-------------+
             |    whatever |
             |-------------|
          1. |  8888888842 |
          2. | 88888888123 |
          3. | 88888888666 |
             +-------------+

        Comment


        • #5
          Thank you

          Comment

          Working...
          X