Announcement

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

  • _"burgiodata.csv invalid name: looping over files in a folder in stata

    I am trying to loop over mutiple csv files in stata but it keeps returning the _"filename.csv invalid name error.

    Code:
    local files : dir "/Users/aartimalik/Dropbox/italy/test-italy" files "*.csv"
    
    display `"`files'"'
            
     foreach file of local `files' {
                
            import delimited using "`file'", clear
                
        }
    There are 3 files in the test-italy folder: burgiodata.csv; montallegrodata.csv; riberadata.csv.

  • #2
    You should remove the single quotes around the name of the local macro in the foreach statement:
    Code:
    foreach file of local files {

    Comment


    • #3
      Originally posted by Hemanshu Kumar View Post
      You should remove the single quotes around the name of the local macro in the foreach statement:
      Code:
      foreach file of local files {
      Thanks. But it still returns the error: file burgiodata.csv not found.

      Comment


      • #4
        That's probably because your current working directory is something other than where the files are located, and you didn't provide the path while invoking import delimited. Try substituting that line with:
        Code:
        import delimited using "/Users/aartimalik/Dropbox/italy/test-italy/`file'", clear

        Comment

        Working...
        X