Announcement

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

  • Looking saving filenames in a directory to a local

    Hi there,

    I'm trying to append a bunch of Excel files together using the following code:
    Code:
    local manyfiles : dir . files "*.xlsx"
    display `"`manyfiles'"'
    
    tempfile manydatasets
    
    foreach file of local manyfiles {
     import excel `"`file'"', clear
     capture append using "`manydatasets'"
     save "`manydatasets'", replace
    }
    However, I am getting the following error:
    Code:
    file ~.xlsx not found
    r(601);
    I do not see any file titled "~.xlsx" in the current directory. Any ideas about what's going on here and how I can get Stata to not try to bring in this file?

    Thanks,
    Erika

  • #2
    It's not clear what's going wrong. I copy/pasted your code into my do-file editor and ran it: it worked perfectly. So the code itself is not the issue.

    It might help if you show us not just the code and the one error message but all of the output that Stata gave to this entire sequence of commands.

    Comment


    • #3
      Perhaps there are too many files in the directory?

      Just because I always do point it out, also see xls2dta from SSC for this problem.

      Code:
      xls2dta , clear : append using *.xlsx
      save manydatasets.dta
      Best
      Daniel

      Comment


      • #4
        You are sure that your excel files are xlsx and not of the xls or xlsb variety?

        Comment


        • #5
          I've also run into this problem when the .xlsx files are password protected - if they are that could be the cause of the error

          Comment


          • #6
            I had a similar issue when there was a "$" sign in the filename. Can you give an example of the file name?

            Comment

            Working...
            X