Announcement

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

  • Delete an observation if the value of a string variable is contained in another variable.

    I want to delete any obervation where the value of input1 is same as that of input_toremove.

    I saw the code below on this forum:
    Code:
    levelsof input_toremove, local(cid)
    levelsof input1, local(oid)
    local diff: list cid - oid
    local todrop: list cid - diff
    local todrop2:  subinstr local todrop " " ",,, all
    di `"`todrop"'
    drop if inlist(input1,`todrop')
    but it seems not to work. Kindly assist.

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str119 input1 str39 input_toremove
    "safety box (firstmed)"                                                         "community health extension worker (pe.."
    "hts ( lab scientist level 12)"                                                 "medical laboratory scientist (ip ad-h.."
    "chairs"                                                                        "face mask (surgical)"                   
    "tables"                                                                        "stipends for airtime and utility"       
    "pmct/hts register"                                                             "table pad (generic)"                    
    "pen (bic brand)"                                                               "counsellor tester (ip-ad hoc)"          
    "client intake form"                                                            "hand washing station"                   
    "geepee  plastic chair with iron legs"                                          "cleaner"                                
    "hand sanitizer (kluvex 500ml)"                                                 "data subscription"                      
    "blood lancets"                                                                 "electric power"                         
    "plastic chairs (rida national)"                                                "electricity"                            
    "water"                                                                         "stipend for communication (mtn airtime)"
    "nurse rn, grade level 8"                                                       "stipend for water bill"                 
    "table"                                                                         "utilities"                              
    "art register"                                                                  "utility bill"                           
    "table pad (generic)"                                                           "1 chair and table"                      
    "wood table"                                                                    "1 long big table"                       
    "hand sanitizer (wind)"                                                         "1 mouse"                                
    "bleach (hypo)"                                                                 "1 stool"                                
    "desktop computer (hp pentium 4)"                                               "1 table"                                
    "community tester"                                                              "1 table per test"                       
    "case manager (ip ad-hoc)"                                                      "1 wooden cabinet"                       
    "ups (blue gate bg 1530 elite pro)"                                             "2 chairs per test"                      
    "art doctor"                                                                    "cabinet set"                            
    "adherence counsellor(ip-adhoc staff)"                                          "chair"                                  
    "hiv client intake form"                                                        "chair(plastic)"                         
    "antiseptic (dettol)"                                                           "chairs"                                 
    "health information technician grade level 6"                                   "desktop"                                
    "lay testers(  cihp adhoc staff)"                                               "desktop computer"                       
    "water"                                                                         "hospital screen"                        
    "clinic matron and supervisor of pocs (principal nurse officer grade level 12)" "plastic chair (white)"                  
    "latex hand gloves (unicare)"                                                   "screen curtain"                         
    "client intake register"                                                        "stool"                                  
    "biohazard safety bag (plain)"                                                  "table"                                  
    "determine"                                                                     "table timer"                            
    ""                                                                              "wooden chair"                           
    "pharmacist"                                                                    "wooden chairs"                          
    "unigold test kit (trinity biotech)"                                            "wooden table"                           
    "hp laptop for registration and documentation"                                  "wooden table (office luxurious with d.."
    "hand sanitizer (wind)"                                                         "2 bulbs can properly light the room f.."
    "medical lab scientist (level 10)"                                              "anc register"                           
    "septol hand sanitizer"                                                         "art register"                           
    "air conditioner(lg ,split unit)"                                               "ballpoint pen (bic plastic blue ink)"   
    "plastic chair (white)"                                                         "ballpoint pen (biro)"                   
    "unigold(trinity biotech)"                                                      "ballpoint pen (vista dollar 0.7mini)"   
    "cupboard (wooden with glass cover and has four layers)"                        "ballpoint pen(bic)"                     
    "uni-gold ( trinity gold bio tech)"                                             "biro"                                   
    "client intake form"                                                            "child follow up register"               
    "laboratory technician (ip ad-hoc staff)"                                       "child follow up register logbook"       
    "referral form"                                                                 "client intake form"                     
    "determine test kits"                                                           "client intake form for index client 101"
    "senior laboratory scientist"                                                   "client intake form for index client 102"
    "cotton wool (agary)"                                                           "client intake forms"                    
    "centrifuge"                                                                    "client referral form"                   
    "personel"                                                                      "contact tracing and tracking form"      
    "uni-gold test kit (trinitybiotech)"                                            "daily hiv & syphilis testing work sheet"
    "metal chair (with arm rest)"                                                   "daily hiv and syphilis testing work s.."
    "medical doctor"                                                                "daily hiv and syphilis testing worksh.."
    "thermometer (dt-8806c body)"                                                   "daily hiv testing worksheet"            
    "cabinet"                                                                       "daily hiv worksheet"                    
    "table timer"                                                                   "daily hts worksheet"                    
    "lab scientist"                                                                 "daily worksheet"                        
    "lancet(sterile lite touch)"                                                    "file jacket"                            
    "ri/oba/3350"                                                                   "file pack"                              
    "wooden bench"                                                                  "genology form"                          
    "laboratory assistant(ip adhoc staff)"                                          "hiv counseling and testing register"    
    "medical lab technician ( gl12)"                                                "hiv daily worksheet"                    
    "methylated spirit"                                                             "hiv preventive poster"                  
    "refrigerator (felicity)"                                                       "hiv request and result form"            
    "laboratory technician grade level 10"                                          "hiv risk assessment tool"               
    "table"                                                                         "hiv risk stratification tool"           
    "wooden table"                                                                  "hiv testing service register"           
    "trimsafe safety box"                                                           "hts client intake form"                 
    "hts registers"                                                                 "hts daily worksheet"                    
    "daily_hiv_testing_worksheet"                                                   "hts monthly summary form"               
    "front desk officer"                                                            "hts referral form"                      
    "latex examination hand gloves (unigloves)"                                     "hts referral register"                  
    "sharp box"                                                                     "hts register"                           
    "disposable delivery mat (divine care)"                                         "hts register (biological children); o.."
    "plastic chair (geepee)"                                                        "hts register (hard cover)"              
    "hand wash apparatus"                                                           "hts register (new cases)"               
    "wooden table"                                                                  "hts register (old adults)"              
    "laboratory technician"                                                         "hts register logbook"                   
    "laboratory scientist, grade level 12"                                          "hts register."                          
    "determine(abbott)"                                                             "hts registers"                          
    "lab_worksheet"                                                                 "hts request and result form"            
    "art nurse"                                                                     "hts request and result logbook"         
    "uni - gold"                                                                    "ict child testing form 202; new cases"  
    "methylated spirit (1l)"                                                        "ict child testing form 202; old cases"  
    "determine test kits (abbot)"                                                   "index contact form"                     
    "industrial training student (intern)"                                          "index register"                         
    "dell core i7 laptop"                                                           "index testing client intake form 101"   
    "data management clerk"                                                         "index testing register"                 
    "pen"                                                                           "index testing register logbook"         
    "safety box"                                                                    "job aids"                               
    "determine"                                                                     "jotter notebook"                        
    "data management clark"                                                         "lab request and result form"            
    "blood pressure apparatus"                                                      "manual guide (job aids)"                
    "solar inverter"                                                                "maternal cohort register"               
    "ad-hoc staff gl 7 (state ministry of health)"                                  "nascp logbook"                          
    end

  • #2
    You are using some very complicated logic with multiple negatives to try to arrive at a list of things to drop, whereas your ultimate goal as stated in your first sentence is rather straightforward. So why not go with the straightforward route:

    Code:
    preserve
    keep input_toremove
    duplicates drop
    rename input_toremove input1
    tempfile to_drop
    save `to_drop'
    
    restore
    merge m:1 input1 using `to_drop', keep(master match)
    drop if _merge == 3

    Comment


    • #3
      Originally posted by Clyde Schechter View Post
      You are using some very complicated logic with multiple negatives to try to arrive at a list of things to drop, whereas your ultimate goal as stated in your first sentence is rather straightforward. So why not go with the straightforward route:

      Code:
      preserve
      keep input_toremove
      duplicates drop
      rename input_toremove input1
      tempfile to_drop
      save `to_drop'
      
      restore
      merge m:1 input1 using `to_drop', keep(master match)
      drop if _merge == 3
      Thanks a lot.

      Comment

      Working...
      X