Announcement

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

  • wht


    . generate wanted = ustrregexra(have,"(?<=.)(.)",",$1")

  • #2
    Code:
     
     . generate wanted = ustrregexra(have,"(?<=.)(.)",",$1")

    Comment


    • #3
      Code:
      clear all
      
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input str2 id str6 have
      "1"  ""      
      "2"  ""      
      "3"  "6"    
      "4"  "2"    
      "5"  "125"  
      "6"  ""      
      "7"  "123456"
      "8"  "136"  
      "9"  "45"    
      "10" ""      
      end
      
      expand `= 10^6 '
      
      forvalues i = 1/10 {
      
          keep id have
          
          timer on 11
          generate wanted_rx11 = ustrregexra(have, "(.)(?=.)", "$1,")
          timer off 11
      
          timer on 12
          generate wanted_rx12 = ustrregexra(have, "(?<=.)(.)", ",$1")
          timer off 12
          
          timer on 21    
          generate wanted_rx21 = ustrregexra(have, "(.)(?=.)","$1,") if !mi(have)
          timer off 21
      
          timer on 22
          generate wanted_rx22 = ustrregexra(have, "(?<=.)(.)", ",$1") if !mi(have)
          timer off 22
          
          timer on 99
          
          gen wanted_99 =  subinstr(trim( substr(have,1,1) + " " ///
              + substr(have,2,1) + " " /// 
              + substr(have,3,1) + " " /// 
              + substr(have,4,1) + " " /// 
              + substr(have,5,1) + " " /// 
              + substr(have,6,1) + " ")," ",",",.)
      
          timer off 99     
      }
      
      assert wanted_rx21 == wanted_rx11          
      assert wanted_rx22 == wanted_rx11
      assert wanted_99   == wanted_rx11
        
      timer list

      Comment

      Working...
      X