Announcement

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

  • Loop code for appending specific sheets in a excel workbook

    Hi! Could you help me write a loop code to import and append specific sheets from an Excel workbook, say sheets named A, B and C? I use Stata 16.

    Thank you for your time and help

  • #2
    Code:
    tempfile myfile
    save `myfile', emptyok
    foreach sheet in  "Name sheet A" "Name Sheet B" "Name Sheet C"{
        import excel "my_Excel_file.xlsx", sheet(`sheet') clear
        append using `myfile'
        save `myfile', replace
    }
    use `myfile', clear

    Comment

    Working...
    X