Announcement

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

  • Stata interpreting the same string value as different values

    I have postcodes in my dataset that I want to group together. As you can see when I type tab Postcode for the majority of values it correctly groups them together. However, for some random postcodes, it counts as different values e.g. CR0 and DA7. I have checked my excel data and it is the same value typed in the cells so I don't understand why Stata identifies it as different values. Does anyone know what the issue might be?

    Code:
    tab Postcode
    
       Postcode |      Freq.     Percent        Cum.
    ------------+-----------------------------------
            BR1 |          3        0.50        0.50
            BR2 |          3        0.50        1.00
            CR0 |          7        1.17        3.34
           CR0  |          2        0.33        3.68
            CR2 |          3        0.50        4.18
            CR4 |          4        0.67        4.85
           DA17 |          5        0.84        6.86
            DA7 |          2        0.33        7.19
           DA7  |          1        0.17        7.36

  • #2
    Very likely that you have trailing spaces for two of your postal codes. Try the following, then see what you get.

    Code:
    replace Postcode = ustrtrim(Postcode)
    tab Postcode

    Comment


    • #3
      Thank you so much for your help! This worked.

      Comment

      Working...
      X