Announcement

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

  • tag to make repeated variables to be one

    Hi

    I am going to make each variable to be only one. I mean for example 122 is repeating three times, I am going to make it be only once. As a result, all values in CCPCodes3 will be shown up once. Any ideas appreciated.


    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float CCPCodes3
    111
    112
    121
    121
    121
    121
    122
    122
    122
    131
    131
    132
    132
    132
    133
    134
    134
    134
    134
    134
    134
    141
    141
    142
    143
    211
    211
    211
    211
    212
    213
    213
    213
    214
    214
    214
    214
    214
    214
    215
    215
    215
    216
    216
    216
    216
    216
    216
    221
    222
    222
    223
    225
    226
    226
    226
    226
    226
    226
    226
    226
    231
    232
    233
    234
    234
    235
    235
    235
    235
    235
    235
    235
    241
    241
    242
    242
    242
    242
    243
    243
    243
    243
    251
    251
    251
    251
    252
    252
    252
    252
    261
    262
    262
    263
    263
    263
    263
    263
    264
    end
    
    . tab CCPCodes3
    
      CCPCodes3 |      Freq.     Percent        Cum.
    ------------+-----------------------------------
            111 |          1        0.27        0.27
            112 |          1        0.27        0.54
            121 |          4        1.07        1.61
            122 |          3        0.80        2.41
            131 |          2        0.54        2.95
            132 |          3        0.80        3.75
            133 |          1        0.27        4.02
            134 |          6        1.61        5.63
            141 |          2        0.54        6.17
            142 |          1        0.27        6.43
            143 |          1        0.27        6.70
            211 |          4        1.07        7.77
            212 |          1        0.27        8.04
            213 |          3        0.80        8.85
            214 |          6        1.61       10.46
            215 |          3        0.80       11.26
            216 |          6        1.61       12.87
            221 |          1        0.27       13.14
            222 |          2        0.54       13.67
            223 |          1        0.27       13.94
    Cheers,
    Paris

  • #2
    Are you wanting to drop repeat observations?
    Code:
    bysort ccpcodes: gen t = _n
    keep if t == 1
    If not, you can recode repeats to missing
    Code:
    bysort ccpcodes: gen t = _n
    replace ccpocodes = . if t != 1

    Comment


    • #3
      Dear Jaycob, Thank you for the reply.

      My answer is neither.
      I want to keep repeated obs once, not totally remove the variable.

      Comment


      • #4
        I used
        Code:
        bysort CCPCodes3: keep if _n == _N
        to keep once for each repeated obs. Hope is correct.

        Comment


        • #5
          Code:
          help duplicates

          Comment

          Working...
          X