Announcement

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

  • Wildcards in file name when importing csv files

    Hi guys,

    I am working a bunch of historical csv files with name like: YYYYMMDD_123_Data.csv The middle part "123" is always a 3 digit random number. I want to build up a loop in stata to import these csv files one by one and do some analysis.

    As we see, the middle part of each csv file is different, is there any wildcard I can use to make Stata recognize each file in the loop? I tried YYYYMMDD_***_Data.csv and it doesn't work.
    If you have any good idea, please feel free to share!

    Thank you for your time!










  • #2
    Hello Miles,

    I don't think you can use wildcards for file names in a loop.

    However, if you put all of your files in the same folder, you could use a macro extended function to grab the list of files for you. In the extended function, you can use wildcards.

    Example:
    Code:
    //All files saved in folder C:\historical_csv
    local files: dir "C:\historical_csv'" files "*.csv"
    foreach file of loc files {
     //MORE CODE
    }

    Comment


    • #3
      Originally posted by Roger Chu View Post
      Hello Miles,

      I don't think you can use wildcards for file names in a loop.

      However, if you put all of your files in the same folder, you could use a macro extended function to grab the list of files for you. In the extended function, you can use wildcards.

      Example:
      Code:
      //All files saved in folder C:\historical_csv
      local files: dir "C:\historical_csv'" files "*.csv"
      foreach file of loc files {
      //MORE CODE
      }
      Hi Roger,

      Thank you so much! It works! I do appreciate your help!!!!

      Regards,
      Miles

      Comment

      Working...
      X