Announcement

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

  • Forvalues loop for appending data not working

    Hello,

    I'm trying to compile a bunch of excel files into a directory, and I've successfully established the directory but I can't seem to successfully convert the .csv files into .dta files to append them. my code is as follows:

    forvalues i = 1/8 {
    clear
    import delimited 'i'.csv
    save 'i'.dta, replace
    }

    I've tinkered a bit but I can't get any results. Please let me know what I'm doing wrong!

    Thank you

  • #2
    To have Stata substitute the value of a local macro
    Code:
     shortcut
    you need to type on your keyboard
    Code:
     `shortcut'
    where the first character is (on an American English keyboard) the "left single quote" beneath the tilde (~) character below the ESC key, and the final character is the usual "single quote" ("apostrophe") just to the left of the RETURN key. Neither of these are "smart quotes" as understood in programs like Microsoft Word, and in particular the first character is correctly titled the "grave accent".

    Comment


    • #3
      Thank you for replying quickly! Where should the shortcut be added in my code?

      Comment


      • #4
        No, you misunderstood #2. There is no shortcut to add. The problem with your code in #1 is the use of ordinary single quotes (') to begin a local macro. Your code should be:
        Code:
        forvalues i = 1/8 {
            clear
            import delimited `i'.csv
            save `i'.dta, replace
        }

        Comment

        Working...
        X