Announcement

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

  • Generating a new variables based on conditions

    Hello, I have a question as to how to generate a variable based on some conditions, I have these relevant variables (CASENUM PHONETYPE PHONENUMBER). I want to generate a new variable that consists of the duplicate cell numbers, so in the example below, there are 4 duplicates, I want to maintain the second, I want this for all cases where there are duplicate CASENUMBERS and cell phones. I hope this question makes sense
    SAPD24111630 Cell

    SAPD24111630 Cell
    SAPD24111630 Cell
    SAPD24111630 Work
    SAPD24111630 Other

    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str12 CASENUM str16 PHONETYPE double PHONENUMBER
    "SAPD24118937" "Cell" 18304316624
    "SAPD24118889" "Cell" 12109791643
    "SAPD24118835" "Cell" 14024994996
    "SAPD24118777" "Cell" 12812544320
    "SAPD24118755" "Cell" 17856141487
    "SAPD24118755" "Cell" 13038701951
    "SAPD24118519" "Cell" 12106053538
    "SAPD24118322" "Cell" 12106438156
    "SAPD24118198" "Cell" 12252784565
    "SAPD24118113" "Cell" 13613433082
    "SAPD24117355" "Cell" 12109622257
    "SAPD24117332" "Cell" 12107711890
    "SAPD24117332" "Home" 17547799
    "SAPD24117332" "Home" 12104452311
    "SAPD24117313" "Cell" 15095928290
    "SAPD24117309" "Cell" 12103866666
    "SAPD24117285" "Cell" 12107710816
    "SAPD24117283" "Home" 16263285
    "SAPD24117283" "Cell" 12104541543
    "SAPD24117155" "Cell" 12108105758
    "SAPD24116684" "Cell" 12105178751
    "SAPD24116652" "Cell" 15614258338
    "SAPD24116633" "Cell" 12107179800
    "SAPD24116617" "Cell" 12547072120
    "SAPD24116556" "Cell" 17262067496
    "SAPD24116238" "Work" 12106890915
    "SAPD24116238" "Cell" 12107168732
    "SAPD24116238" "Other" 12105733008
    "SAPD24115375" "Cell" 12102871475
    "SAPD24115319" "Other" 12104265972
    "SAPD24115279" "" .
    "SAPD24115279" "Cell" 18325854444
    "SAPD24115247" "Cell" 12108484932
    "SAPD24114875" "Cell" 18305818695
    "SAPD24114836" "Work" 12103662304
    "SAPD24114836" "Home" 14796002
    "SAPD24114836" "Other" 12102136075
    "SAPD24114836" "Other" 12102136975
    "SAPD24114824" "Home" 12102871383
    "SAPD24114824" "Cell" 13614459044
    "SAPD24114824" "Other" 18303050607
    "SAPD24114770" "Other" 12103855645
    "SAPD24114759" "Cell" 18306942226
    "SAPD24114692" "Cell" 12145639030
    "SAPD24114658" "Work" 12102062238
    "SAPD24114658" "Cell" 12103780789
    "SAPD24114544" "Cell" 17263339822
    "SAPD24114451" "Cell" 12106300710
    "SAPD24114368" "Cell" 14328160330
    "SAPD24114342" "Other" 12109877906
    "SAPD24114271" "Cell" 12103859859
    "SAPD24114255" "Cell" 12102515863
    "SAPD24114025" "Cell" 19542257783
    "SAPD24113868" "Cell" 13526344163
    "SAPD24113859" "Cell" 19404358533
    "SAPD24113829" "Work" 12104106553
    "SAPD24113829" "Other" 18305708881
    "SAPD24113799" "Cell" 14328894618
    "SAPD24113799" "Cell" 14328892030
    "SAPD24113740" "Cell" 14328038084
    "SAPD24113630" "Cell" 17872426437
    "SAPD24113458" "Cell" 16083439978
    "SAPD24113439" "Cell" 12102547088
    "SAPD24113428" "Cell" 18315962388
    "SAPD24113306" "Cell" 12104730533
    "SAPD24113212" "Cell" 12102907162
    "SAPD24113212" "Cell" 12102942307
    "SAPD24113193" "Cell" 19034531168
    "SAPD24113108" "Cell" 17262094027
    "SAPD24111630" "Cell" 17267770236
    "SAPD24111630" "Cell" 12107945931
    "SAPD24111630" "Work" 12105341874
    "SAPD24111630" "Other" 12104655628
    "SAPD24111551" "Cell" 12108129810
    "SAPD24111487" "Cell" 15596946571
    "SAPD24111414" "Cell" 18303189541
    "SAPD24111414" "Other" 12107794694
    "SAPD24111379" "Cell" 12103653666
    "SAPD24110966" "Cell" 18325840971
    "SAPD24110660" "Cell" 12108595319
    "SAPD24110498" "Cell" 12105890399
    "SAPD24110011" "Cell" 12103320671
    "SAPD24109950" "Cell" 12104390646
    "SAPD24109941" "Cell" 17209660481
    "SAPD24109786" "Cell" 18329357982
    "SAPD24109677" "Cell" 12108834344
    "SAPD24108872" "" .
    "SAPD24108807" "Cell" 18305131205
    "SAPD24108746" "Cell" 12106680556
    "SAPD24108727" "Cell" 19562363062
    "SAPD24108472" "Home" 19033609332
    "SAPD24108472" "Cell" 12103800924
    "SAPD24108472" "Cell" 12107276540
    "SAPD24108372" "Cell" 12105961760
    "SAPD24108372" "Cell" 12106678965
    "SAPD24108326" "Cell" 19794804347
    "SAPD24108235" "" .
    "SAPD24108235" "Cell" 12108127268
    "SAPD24108217" "Cell" 18169165169
    "SAPD24107440" "Cell" 14694505791
    end
    [/CODE]
    ------------------ copy up to and including the previous line ----------------


  • #2
    This is not clear, but I assume that you want a single record per CASENUM PHONETYPE combination.

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str12 CASENUM str16 PHONETYPE double PHONENUMBER
    "SAPD24118937" "Cell" 18304316624
    "SAPD24118889" "Cell" 12109791643
    "SAPD24118835" "Cell" 14024994996
    "SAPD24118777" "Cell" 12812544320
    "SAPD24118755" "Cell" 17856141487
    "SAPD24118755" "Cell" 13038701951
    "SAPD24118519" "Cell" 12106053538
    "SAPD24118322" "Cell" 12106438156
    "SAPD24118198" "Cell" 12252784565
    "SAPD24118113" "Cell" 13613433082
    "SAPD24117355" "Cell" 12109622257
    "SAPD24117332" "Cell" 12107711890
    "SAPD24117332" "Home" 17547799
    "SAPD24117332" "Home" 12104452311
    "SAPD24117313" "Cell" 15095928290
    "SAPD24117309" "Cell" 12103866666
    "SAPD24117285" "Cell" 12107710816
    "SAPD24117283" "Home" 16263285
    "SAPD24117283" "Cell" 12104541543
    "SAPD24117155" "Cell" 12108105758
    "SAPD24116684" "Cell" 12105178751
    "SAPD24116652" "Cell" 15614258338
    "SAPD24116633" "Cell" 12107179800
    "SAPD24116617" "Cell" 12547072120
    "SAPD24116556" "Cell" 17262067496
    "SAPD24116238" "Work" 12106890915
    "SAPD24116238" "Cell" 12107168732
    "SAPD24116238" "Other" 12105733008
    "SAPD24115375" "Cell" 12102871475
    "SAPD24115319" "Other" 12104265972
    "SAPD24115279" "" .
    "SAPD24115279" "Cell" 18325854444
    "SAPD24115247" "Cell" 12108484932
    "SAPD24114875" "Cell" 18305818695
    "SAPD24114836" "Work" 12103662304
    "SAPD24114836" "Home" 14796002
    "SAPD24114836" "Other" 12102136075
    "SAPD24114836" "Other" 12102136975
    "SAPD24114824" "Home" 12102871383
    "SAPD24114824" "Cell" 13614459044
    "SAPD24114824" "Other" 18303050607
    "SAPD24114770" "Other" 12103855645
    "SAPD24114759" "Cell" 18306942226
    "SAPD24114692" "Cell" 12145639030
    "SAPD24114658" "Work" 12102062238
    "SAPD24114658" "Cell" 12103780789
    "SAPD24114544" "Cell" 17263339822
    "SAPD24114451" "Cell" 12106300710
    "SAPD24114368" "Cell" 14328160330
    "SAPD24114342" "Other" 12109877906
    "SAPD24114271" "Cell" 12103859859
    "SAPD24114255" "Cell" 12102515863
    "SAPD24114025" "Cell" 19542257783
    "SAPD24113868" "Cell" 13526344163
    "SAPD24113859" "Cell" 19404358533
    "SAPD24113829" "Work" 12104106553
    "SAPD24113829" "Other" 18305708881
    "SAPD24113799" "Cell" 14328894618
    "SAPD24113799" "Cell" 14328892030
    "SAPD24113740" "Cell" 14328038084
    "SAPD24113630" "Cell" 17872426437
    "SAPD24113458" "Cell" 16083439978
    "SAPD24113439" "Cell" 12102547088
    "SAPD24113428" "Cell" 18315962388
    "SAPD24113306" "Cell" 12104730533
    "SAPD24113212" "Cell" 12102907162
    "SAPD24113212" "Cell" 12102942307
    "SAPD24113193" "Cell" 19034531168
    "SAPD24113108" "Cell" 17262094027
    "SAPD24111630" "Cell" 17267770236
    "SAPD24111630" "Cell" 12107945931
    "SAPD24111630" "Work" 12105341874
    "SAPD24111630" "Other" 12104655628
    "SAPD24111551" "Cell" 12108129810
    "SAPD24111487" "Cell" 15596946571
    "SAPD24111414" "Cell" 18303189541
    "SAPD24111414" "Other" 12107794694
    "SAPD24111379" "Cell" 12103653666
    "SAPD24110966" "Cell" 18325840971
    "SAPD24110660" "Cell" 12108595319
    "SAPD24110498" "Cell" 12105890399
    "SAPD24110011" "Cell" 12103320671
    "SAPD24109950" "Cell" 12104390646
    "SAPD24109941" "Cell" 17209660481
    "SAPD24109786" "Cell" 18329357982
    "SAPD24109677" "Cell" 12108834344
    "SAPD24108872" "" .
    "SAPD24108807" "Cell" 18305131205
    "SAPD24108746" "Cell" 12106680556
    "SAPD24108727" "Cell" 19562363062
    "SAPD24108472" "Home" 19033609332
    "SAPD24108472" "Cell" 12103800924
    "SAPD24108472" "Cell" 12107276540
    "SAPD24108372" "Cell" 12105961760
    "SAPD24108372" "Cell" 12106678965
    "SAPD24108326" "Cell" 19794804347
    "SAPD24108235" "" .
    "SAPD24108235" "Cell" 12108127268
    "SAPD24108217" "Cell" 18169165169
    "SAPD24107440" "Cell" 14694505791
    end
    
    bys CASENUM PHONETYPE: gen which=_n
    reshape wide PHONENUMBER, i(CASENUM PHONETYPE) j(which)
    Res.:

    Code:
    . format PHONENUMBER? %25.0f
    
    . l, sep(0)
    
         +-----------------------------------------------------+
         |      CASENUM   PHONET~E   PHONENUMB~1   PHONENUMB~2 |
         |-----------------------------------------------------|
      1. | SAPD24107440       Cell   14694505791             . |
      2. | SAPD24108217       Cell   18169165169             . |
      3. | SAPD24108235                        .             . |
      4. | SAPD24108235       Cell   12108127268             . |
      5. | SAPD24108326       Cell   19794804347             . |
      6. | SAPD24108372       Cell   12105961760   12106678965 |
      7. | SAPD24108472       Cell   12103800924   12107276540 |
      8. | SAPD24108472       Home   19033609332             . |
      9. | SAPD24108727       Cell   19562363062             . |
     10. | SAPD24108746       Cell   12106680556             . |
     11. | SAPD24108807       Cell   18305131205             . |
     12. | SAPD24108872                        .             . |
     13. | SAPD24109677       Cell   12108834344             . |
     14. | SAPD24109786       Cell   18329357982             . |
     15. | SAPD24109941       Cell   17209660481             . |
     16. | SAPD24109950       Cell   12104390646             . |
     17. | SAPD24110011       Cell   12103320671             . |
     18. | SAPD24110498       Cell   12105890399             . |
     19. | SAPD24110660       Cell   12108595319             . |
     20. | SAPD24110966       Cell   18325840971             . |
     21. | SAPD24111379       Cell   12103653666             . |
     22. | SAPD24111414       Cell   18303189541             . |
     23. | SAPD24111414      Other   12107794694             . |
     24. | SAPD24111487       Cell   15596946571             . |
     25. | SAPD24111551       Cell   12108129810             . |
     26. | SAPD24111630       Cell   17267770236   12107945931 |
     27. | SAPD24111630      Other   12104655628             . |
     28. | SAPD24111630       Work   12105341874             . |
     29. | SAPD24113108       Cell   17262094027             . |
     30. | SAPD24113193       Cell   19034531168             . |
     31. | SAPD24113212       Cell   12102942307   12102907162 |
     32. | SAPD24113306       Cell   12104730533             . |
     33. | SAPD24113428       Cell   18315962388             . |
     34. | SAPD24113439       Cell   12102547088             . |
     35. | SAPD24113458       Cell   16083439978             . |
     36. | SAPD24113630       Cell   17872426437             . |
     37. | SAPD24113740       Cell   14328038084             . |
     38. | SAPD24113799       Cell   14328894618   14328892030 |
     39. | SAPD24113829      Other   18305708881             . |
     40. | SAPD24113829       Work   12104106553             . |
     41. | SAPD24113859       Cell   19404358533             . |
     42. | SAPD24113868       Cell   13526344163             . |
     43. | SAPD24114025       Cell   19542257783             . |
     44. | SAPD24114255       Cell   12102515863             . |
     45. | SAPD24114271       Cell   12103859859             . |
     46. | SAPD24114342      Other   12109877906             . |
     47. | SAPD24114368       Cell   14328160330             . |
     48. | SAPD24114451       Cell   12106300710             . |
     49. | SAPD24114544       Cell   17263339822             . |
     50. | SAPD24114658       Cell   12103780789             . |
     51. | SAPD24114658       Work   12102062238             . |
     52. | SAPD24114692       Cell   12145639030             . |
     53. | SAPD24114759       Cell   18306942226             . |
     54. | SAPD24114770      Other   12103855645             . |
     55. | SAPD24114824       Cell   13614459044             . |
     56. | SAPD24114824       Home   12102871383             . |
     57. | SAPD24114824      Other   18303050607             . |
     58. | SAPD24114836       Home      14796002             . |
     59. | SAPD24114836      Other   12102136075   12102136975 |
     60. | SAPD24114836       Work   12103662304             . |
     61. | SAPD24114875       Cell   18305818695             . |
     62. | SAPD24115247       Cell   12108484932             . |
     63. | SAPD24115279                        .             . |
     64. | SAPD24115279       Cell   18325854444             . |
     65. | SAPD24115319      Other   12104265972             . |
     66. | SAPD24115375       Cell   12102871475             . |
     67. | SAPD24116238       Cell   12107168732             . |
     68. | SAPD24116238      Other   12105733008             . |
     69. | SAPD24116238       Work   12106890915             . |
     70. | SAPD24116556       Cell   17262067496             . |
     71. | SAPD24116617       Cell   12547072120             . |
     72. | SAPD24116633       Cell   12107179800             . |
     73. | SAPD24116652       Cell   15614258338             . |
     74. | SAPD24116684       Cell   12105178751             . |
     75. | SAPD24117155       Cell   12108105758             . |
     76. | SAPD24117283       Cell   12104541543             . |
     77. | SAPD24117283       Home      16263285             . |
     78. | SAPD24117285       Cell   12107710816             . |
     79. | SAPD24117309       Cell   12103866666             . |
     80. | SAPD24117313       Cell   15095928290             . |
     81. | SAPD24117332       Cell   12107711890             . |
     82. | SAPD24117332       Home      17547799   12104452311 |
     83. | SAPD24117355       Cell   12109622257             . |
     84. | SAPD24118113       Cell   13613433082             . |
     85. | SAPD24118198       Cell   12252784565             . |
     86. | SAPD24118322       Cell   12106438156             . |
     87. | SAPD24118519       Cell   12106053538             . |
     88. | SAPD24118755       Cell   17856141487   13038701951 |
     89. | SAPD24118777       Cell   12812544320             . |
     90. | SAPD24118835       Cell   14024994996             . |
     91. | SAPD24118889       Cell   12109791643             . |
     92. | SAPD24118937       Cell   18304316624             . |
         +-----------------------------------------------------+
    
    .
    Last edited by Andrew Musau; 09 Jul 2024, 15:59.

    Comment


    • #3
      Originally posted by Andrew Musau View Post
      This is not clear, but I assume that you want a single record per CASENUM PHONETYPE combination.

      Code:
      * Example generated by -dataex-. For more info, type help dataex
      clear
      input str12 CASENUM str16 PHONETYPE double PHONENUMBER
      "SAPD24118937" "Cell" 18304316624
      "SAPD24118889" "Cell" 12109791643
      "SAPD24118835" "Cell" 14024994996
      "SAPD24118777" "Cell" 12812544320
      "SAPD24118755" "Cell" 17856141487
      "SAPD24118755" "Cell" 13038701951
      "SAPD24118519" "Cell" 12106053538
      "SAPD24118322" "Cell" 12106438156
      "SAPD24118198" "Cell" 12252784565
      "SAPD24118113" "Cell" 13613433082
      "SAPD24117355" "Cell" 12109622257
      "SAPD24117332" "Cell" 12107711890
      "SAPD24117332" "Home" 17547799
      "SAPD24117332" "Home" 12104452311
      "SAPD24117313" "Cell" 15095928290
      "SAPD24117309" "Cell" 12103866666
      "SAPD24117285" "Cell" 12107710816
      "SAPD24117283" "Home" 16263285
      "SAPD24117283" "Cell" 12104541543
      "SAPD24117155" "Cell" 12108105758
      "SAPD24116684" "Cell" 12105178751
      "SAPD24116652" "Cell" 15614258338
      "SAPD24116633" "Cell" 12107179800
      "SAPD24116617" "Cell" 12547072120
      "SAPD24116556" "Cell" 17262067496
      "SAPD24116238" "Work" 12106890915
      "SAPD24116238" "Cell" 12107168732
      "SAPD24116238" "Other" 12105733008
      "SAPD24115375" "Cell" 12102871475
      "SAPD24115319" "Other" 12104265972
      "SAPD24115279" "" .
      "SAPD24115279" "Cell" 18325854444
      "SAPD24115247" "Cell" 12108484932
      "SAPD24114875" "Cell" 18305818695
      "SAPD24114836" "Work" 12103662304
      "SAPD24114836" "Home" 14796002
      "SAPD24114836" "Other" 12102136075
      "SAPD24114836" "Other" 12102136975
      "SAPD24114824" "Home" 12102871383
      "SAPD24114824" "Cell" 13614459044
      "SAPD24114824" "Other" 18303050607
      "SAPD24114770" "Other" 12103855645
      "SAPD24114759" "Cell" 18306942226
      "SAPD24114692" "Cell" 12145639030
      "SAPD24114658" "Work" 12102062238
      "SAPD24114658" "Cell" 12103780789
      "SAPD24114544" "Cell" 17263339822
      "SAPD24114451" "Cell" 12106300710
      "SAPD24114368" "Cell" 14328160330
      "SAPD24114342" "Other" 12109877906
      "SAPD24114271" "Cell" 12103859859
      "SAPD24114255" "Cell" 12102515863
      "SAPD24114025" "Cell" 19542257783
      "SAPD24113868" "Cell" 13526344163
      "SAPD24113859" "Cell" 19404358533
      "SAPD24113829" "Work" 12104106553
      "SAPD24113829" "Other" 18305708881
      "SAPD24113799" "Cell" 14328894618
      "SAPD24113799" "Cell" 14328892030
      "SAPD24113740" "Cell" 14328038084
      "SAPD24113630" "Cell" 17872426437
      "SAPD24113458" "Cell" 16083439978
      "SAPD24113439" "Cell" 12102547088
      "SAPD24113428" "Cell" 18315962388
      "SAPD24113306" "Cell" 12104730533
      "SAPD24113212" "Cell" 12102907162
      "SAPD24113212" "Cell" 12102942307
      "SAPD24113193" "Cell" 19034531168
      "SAPD24113108" "Cell" 17262094027
      "SAPD24111630" "Cell" 17267770236
      "SAPD24111630" "Cell" 12107945931
      "SAPD24111630" "Work" 12105341874
      "SAPD24111630" "Other" 12104655628
      "SAPD24111551" "Cell" 12108129810
      "SAPD24111487" "Cell" 15596946571
      "SAPD24111414" "Cell" 18303189541
      "SAPD24111414" "Other" 12107794694
      "SAPD24111379" "Cell" 12103653666
      "SAPD24110966" "Cell" 18325840971
      "SAPD24110660" "Cell" 12108595319
      "SAPD24110498" "Cell" 12105890399
      "SAPD24110011" "Cell" 12103320671
      "SAPD24109950" "Cell" 12104390646
      "SAPD24109941" "Cell" 17209660481
      "SAPD24109786" "Cell" 18329357982
      "SAPD24109677" "Cell" 12108834344
      "SAPD24108872" "" .
      "SAPD24108807" "Cell" 18305131205
      "SAPD24108746" "Cell" 12106680556
      "SAPD24108727" "Cell" 19562363062
      "SAPD24108472" "Home" 19033609332
      "SAPD24108472" "Cell" 12103800924
      "SAPD24108472" "Cell" 12107276540
      "SAPD24108372" "Cell" 12105961760
      "SAPD24108372" "Cell" 12106678965
      "SAPD24108326" "Cell" 19794804347
      "SAPD24108235" "" .
      "SAPD24108235" "Cell" 12108127268
      "SAPD24108217" "Cell" 18169165169
      "SAPD24107440" "Cell" 14694505791
      end
      
      bys CASENUM PHONETYPE: gen which=_n
      reshape wide PHONENUMBER, i(CASENUM PHONETYPE) j(which)
      Res.:

      Code:
      . format PHONENUMBER? %25.0f
      
      . l, sep(0)
      
      +-----------------------------------------------------+
      | CASENUM PHONET~E PHONENUMB~1 PHONENUMB~2 |
      |-----------------------------------------------------|
      1. | SAPD24107440 Cell 14694505791 . |
      2. | SAPD24108217 Cell 18169165169 . |
      3. | SAPD24108235 . . |
      4. | SAPD24108235 Cell 12108127268 . |
      5. | SAPD24108326 Cell 19794804347 . |
      6. | SAPD24108372 Cell 12105961760 12106678965 |
      7. | SAPD24108472 Cell 12103800924 12107276540 |
      8. | SAPD24108472 Home 19033609332 . |
      9. | SAPD24108727 Cell 19562363062 . |
      10. | SAPD24108746 Cell 12106680556 . |
      11. | SAPD24108807 Cell 18305131205 . |
      12. | SAPD24108872 . . |
      13. | SAPD24109677 Cell 12108834344 . |
      14. | SAPD24109786 Cell 18329357982 . |
      15. | SAPD24109941 Cell 17209660481 . |
      16. | SAPD24109950 Cell 12104390646 . |
      17. | SAPD24110011 Cell 12103320671 . |
      18. | SAPD24110498 Cell 12105890399 . |
      19. | SAPD24110660 Cell 12108595319 . |
      20. | SAPD24110966 Cell 18325840971 . |
      21. | SAPD24111379 Cell 12103653666 . |
      22. | SAPD24111414 Cell 18303189541 . |
      23. | SAPD24111414 Other 12107794694 . |
      24. | SAPD24111487 Cell 15596946571 . |
      25. | SAPD24111551 Cell 12108129810 . |
      26. | SAPD24111630 Cell 17267770236 12107945931 |
      27. | SAPD24111630 Other 12104655628 . |
      28. | SAPD24111630 Work 12105341874 . |
      29. | SAPD24113108 Cell 17262094027 . |
      30. | SAPD24113193 Cell 19034531168 . |
      31. | SAPD24113212 Cell 12102942307 12102907162 |
      32. | SAPD24113306 Cell 12104730533 . |
      33. | SAPD24113428 Cell 18315962388 . |
      34. | SAPD24113439 Cell 12102547088 . |
      35. | SAPD24113458 Cell 16083439978 . |
      36. | SAPD24113630 Cell 17872426437 . |
      37. | SAPD24113740 Cell 14328038084 . |
      38. | SAPD24113799 Cell 14328894618 14328892030 |
      39. | SAPD24113829 Other 18305708881 . |
      40. | SAPD24113829 Work 12104106553 . |
      41. | SAPD24113859 Cell 19404358533 . |
      42. | SAPD24113868 Cell 13526344163 . |
      43. | SAPD24114025 Cell 19542257783 . |
      44. | SAPD24114255 Cell 12102515863 . |
      45. | SAPD24114271 Cell 12103859859 . |
      46. | SAPD24114342 Other 12109877906 . |
      47. | SAPD24114368 Cell 14328160330 . |
      48. | SAPD24114451 Cell 12106300710 . |
      49. | SAPD24114544 Cell 17263339822 . |
      50. | SAPD24114658 Cell 12103780789 . |
      51. | SAPD24114658 Work 12102062238 . |
      52. | SAPD24114692 Cell 12145639030 . |
      53. | SAPD24114759 Cell 18306942226 . |
      54. | SAPD24114770 Other 12103855645 . |
      55. | SAPD24114824 Cell 13614459044 . |
      56. | SAPD24114824 Home 12102871383 . |
      57. | SAPD24114824 Other 18303050607 . |
      58. | SAPD24114836 Home 14796002 . |
      59. | SAPD24114836 Other 12102136075 12102136975 |
      60. | SAPD24114836 Work 12103662304 . |
      61. | SAPD24114875 Cell 18305818695 . |
      62. | SAPD24115247 Cell 12108484932 . |
      63. | SAPD24115279 . . |
      64. | SAPD24115279 Cell 18325854444 . |
      65. | SAPD24115319 Other 12104265972 . |
      66. | SAPD24115375 Cell 12102871475 . |
      67. | SAPD24116238 Cell 12107168732 . |
      68. | SAPD24116238 Other 12105733008 . |
      69. | SAPD24116238 Work 12106890915 . |
      70. | SAPD24116556 Cell 17262067496 . |
      71. | SAPD24116617 Cell 12547072120 . |
      72. | SAPD24116633 Cell 12107179800 . |
      73. | SAPD24116652 Cell 15614258338 . |
      74. | SAPD24116684 Cell 12105178751 . |
      75. | SAPD24117155 Cell 12108105758 . |
      76. | SAPD24117283 Cell 12104541543 . |
      77. | SAPD24117283 Home 16263285 . |
      78. | SAPD24117285 Cell 12107710816 . |
      79. | SAPD24117309 Cell 12103866666 . |
      80. | SAPD24117313 Cell 15095928290 . |
      81. | SAPD24117332 Cell 12107711890 . |
      82. | SAPD24117332 Home 17547799 12104452311 |
      83. | SAPD24117355 Cell 12109622257 . |
      84. | SAPD24118113 Cell 13613433082 . |
      85. | SAPD24118198 Cell 12252784565 . |
      86. | SAPD24118322 Cell 12106438156 . |
      87. | SAPD24118519 Cell 12106053538 . |
      88. | SAPD24118755 Cell 17856141487 13038701951 |
      89. | SAPD24118777 Cell 12812544320 . |
      90. | SAPD24118835 Cell 14024994996 . |
      91. | SAPD24118889 Cell 12109791643 . |
      92. | SAPD24118937 Cell 18304316624 . |
      +-----------------------------------------------------+
      
      .
      Hello, I want one copy per observation if PHONETYPE is Cell and I only want to preserve the second cell number in a separate column, so in the situation below where there are 2 cell phone numbers for the CASENUM (SAPD24108472) I would like only the phone number 12107276540 to appear in a second column.


      SAPD24108326 Cell 19794804347 . | 6. | SAPD24108372 Cell 12105961760 12106678965 | 7. | SAPD24108472 Cell 12103800924 12107276540 |
      Last edited by Luis Mijares Castaneda; 10 Jul 2024, 07:44.

      Comment


      • #4
        Append to the code in #2:

        Code:
        bys CASENUM: egen tag= max(PHONETYPE=="Cell" & !missing(PHONENUMBER2)) 
        bys CASENUM: drop if PHONETYPE!="Cell" & _N>1 & tag
        drop tag

        Comment

        Working...
        X