Announcement

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

  • Interpretation of filelist code

    The procedure I am using works just fine. The problem is, I don't really understand it at all. Is anyone able to interpret this line? I've searched help files and the forum, but haven't gotten anywhere.
    What is the function of the colon? Is "files" a command?

    Code:
    local myfilelist : dir . files "*.txt"

  • #2
    This command is reading all files that match "*.txt" in the current dir (because of . ) and saving them in the local myfilelist.

    It would be useful if later you have a loop that does something to each file, like:
    Code:
    local myfilelist : dir . files "*.txt"
    foreach file of local myfilelist {
     import delimited using("`file'"), clear
     *other things
    }
    You can see more details in the help file that pops up when typing "help dir"
    Last edited by diana gold; 13 Nov 2019, 20:48.

    Comment


    • #3
      To add to the answer from diana gold if you look at the output of the help local command you will see on one of the initial lines
      Code:
              local    lclname [=exp | :macro_fcn | "[string]" | `"[string]"']
      and if you click on :macro_fcn it will scroll down a few lines to where the "macro functions" like dir are described. The dir macro function has much in common with the dir command described by help dir but it is different.

      The function of the colon is to announce to the local command that what follows is a macro function, rather than a Stata expression which would follow an equal sign.
      Last edited by William Lisowski; 13 Nov 2019, 21:18.

      Comment

      Working...
      X