Announcement

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

  • Open files in the same folder using local

    Hi everyone. I'm a Stata beginner so I'm still new with macros. I'm trying to open, edit then save multiple files in the same folder. I've read similar posts and followed solutions about this particular topic but my code is not working. Specifically, in the folder "household2004", I have multiple files that start with "hh". When I ran the do file, I got the error "2. is not a valid command name r(199)".

    clear
    cd "...\household2004"
    local files: dir . files "hh*.dta" //I checked by typing "display `files' and it showed me a list of the files I want to process
    foreach f of local files {
    2. use ` f ', clear
    3. (editing)
    4. save ` f ', replace
    5. }

    Thank you for your help

  • #2
    Stata types 2. 3. 4. 5. here but you shouldn't type those numbers yourself in code that you run.

    Comment


    • #3
      Hi Nick,
      I didn't type those numbers. However, I just ran the code again and it worked. Thank you for taking your time to answer my question.

      Comment


      • #4
        Stata told you

        Code:
        2. is not a valid command name
        and that is difficult to explain unless your command line started that way.

        Comment

        Working...
        X