Announcement

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

  • Wild card for a variable list

    I want to delete a bunch of files that have the number 750/773 at the end after combining them all. The files star with Kde_ but have additional words like Kde_theft, Kde_theftday, etc. (Kde_theft750/Kde_theft770).

    How can I use a wildcard to prevent having to write each variable name down? So instead of having to write out all of Kde_theft, Kde_theftday, etc. ?

    foreach i of numlist 750/773 {
    foreach j in Kde_theft {
    rm `j'`i'.dta
    }
    }

  • #2
    There is no wildcard for filenames that will cover a numeric range. But you can accomplish your task without having to make a long list by starting with a wildcard to determine all files starting with Kde_, and then filtering to those that end in a number between 750 and 773:
    Code:
    local start: dir "." files "Kde_*.dta"
    
    foreach f of local start {
        local finish = substr("`f'", -7, 3)
        if inrange(real(`"`finish'"'), 750, 773) {
            rm `"`f'"'
        }
    }

    Comment


    • #3
      I think

      Code:
      if inrange("`finish'", "750", "773")
      should work too.

      Comment


      • #4
        Clyde your code worked perfectly! Thank you.

        Comment

        Working...
        X