Announcement

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

  • renaming multiple dta files

    I have multiple .dta files with complicated names which i want to substring from and rename to a simple format.
    i get the following error:
    invalid syntax
    r(198);


    my command:


    clear
    set more off
    local folder "U:\Blah"
    local files : dir "`folder'" files "*.dta"
    foreach file of local files {
    local name = subinstr("`file'",15,13)
    !rename "file" "name"
    }




  • #2
    I see two problems here. First, the subinstr function is missing an element because the syntax is:
    Code:
    subinstr(s1,s2,s3,n)
    Second, you have to enclose the name of the local name in single quotes.
    Code:
    !rename "file" "`name'"
    The information that you posted doesn't show which command returns the "invalid syntax" error. I guess it's related to the use of subinstr but it is not clear. For future reference (and as mentioned here), please follow this advice from the FAQ:

    Say exactly what you typed and exactly what Stata typed (or did) in response. N.B. exactly!
    Providing complete information makes it easier for other list members to help.

    Comment

    Working...
    X