Dear Statalisters,
I am trying to import several Excel sheets within one workbook and save them individually as Stata files, then loop over the saved datasets and append them in one Stata file. I was inspired by previous posts to write the code below, but I keep receiving this error message "no; data in memory would be lost". Only the first sheet is saved. I am attaching the file for easy reference and verification. Any help is highly appreciated.
Kind regards,
Imed.
code:
import excel using gdpg.xlsx, describe
forvalues i=1/`=r(N_worksheet)' {
local sheetname=r(worksheet_`i')
import excel using gdpg.xlsx, sheet("`sheetname'") firstrow
tempfile file_`sheetname'
save "`file_`sheetname''" , replace
}
* loop over the saved datasets and append them
clear
use "`file_sheet1'"
forvalues i=2/`=r(N_worksheet)' {
append using "`file_sheet`i''"
}
I am trying to import several Excel sheets within one workbook and save them individually as Stata files, then loop over the saved datasets and append them in one Stata file. I was inspired by previous posts to write the code below, but I keep receiving this error message "no; data in memory would be lost". Only the first sheet is saved. I am attaching the file for easy reference and verification. Any help is highly appreciated.
Kind regards,
Imed.
code:
import excel using gdpg.xlsx, describe
forvalues i=1/`=r(N_worksheet)' {
local sheetname=r(worksheet_`i')
import excel using gdpg.xlsx, sheet("`sheetname'") firstrow
tempfile file_`sheetname'
save "`file_`sheetname''" , replace
}
* loop over the saved datasets and append them
clear
use "`file_sheet1'"
forvalues i=2/`=r(N_worksheet)' {
append using "`file_sheet`i''"
}
Comment