Announcement

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

  • import delimited and loop

    Dear Statalisters,
    i am trying to import 40 csv files into one dta file using import delimted and foreachloop. Each file has 2 variables, and they are the same variable for the 40 files. i run the code below, but it only imports one file. thanks in advance for your help


    Code:
    cd "/Users/aarredouani/Desktop/aa"
    local list : dir "/Users/aarredouani/Desktop/aa" files "*.csv"
    foreach f of local list {
    import delimited "`f'"
    save "`f'.dta", replace
    append using "`f'.dta"
    
    }

    stata 15.1 mac

  • #2
    Try adding the -clear- option to the import delimited command.

    Comment


    • #3
      Many thanks but it not work

      Comment


      • #4
        Code:
        cd "/Users/aarredouani/Desktop/aa"
        local list : dir "/Users/aarredouani/Desktop/aa" files "*.csv"
        foreach f of local list {
            import delimited "`f'", clear
            save "`f'.dta", replace
            local append `append' "`f'.dta"
        }
        clear
        append using `append'

        Comment

        Working...
        X