Announcement

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

  • #16
    I found a solution for a) and b), except for the parentheses:

    Code:
    gen Instrument=""
    replace first = ustrregexs(0) if ustrregexm(CompanyInstrument, "[\d+\s?\d+?\s?/?\d+?\s?]+%.*")
    
    gen Company = subinstr(CompanyInstrument, first, "", .) 
    
    gen Instrument2 = "" 
    foreach w in Cum. Pref. {
      replace Instrument2 = Instrument2 + "`w' " if strpos(Company, "`w'")
    } 
    
    gen Instrument_final = Instrument + Instrument2

    Comment


    • #17
      Originally posted by Clyde Schechter View Post
      I don't believe your loop does what you say it does, but it also doesn't do what you want. Try this:

      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input str22 name
      "AAH DEAD"
      "AB AIRLINES DEAD"
      "AB CONSULTING ALIVE"
      "AB DYNAMICS DON'T KNOW"
      "AB ELTN.PRDS."
      "ABACUS GROUP DEAD"
      end
      
      foreach scenario in DEAD ALIVE "DON'T KNOW"{
      local target = reverse(`"`scenario'"')
      local length = length(`"`target'"')
      replace name = reverse(subinstr(reverse(name), "`target' ", "", 1)) ///
      if substr(name, length(name)-`length', `=`length'+1') == `" `scenario'"'
      }
      In the future, please use the -dataex- command to show example data, as I have done here. It greatly simplifies the process of replicating your Stata example in another person's Stata, so that code can be tested on it. If you are running version 15.1, -dataex- is part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it.
      Hi @Clyde Schechter , thanks for your attention. I know it's been over many years, just wanna ask a quick question about your code here. Does it only work if the words (DEAD ALIVE "DON'T KNOW") are positioned at the last at the string? It seems not working for words positioning at the begining of the string.

      Comment

      Working...
      X