Hi,
I'm now trying to combine multiples excel sheets from multiple excel files. I want to get one excel file with respective sheets as combine. These excel files are in the same folder. The variables for each sheet of each excel file are the same.
My code is below and the sample excels files and combined file at the attachment.
I'm trying the below code, the result is not the way that I want, please suggest me.
local xlsx : dir "$outputs\fb"files"*.xlsx"
di `xlsx'
import excel using "$outputs\fb\hfc_outputs_hvs_sup_22_1sep2020.xlsx" , desc
return list
local worksheets `r(N_worksheet)'
display `worksheets'
*set trace on
forvalues i = 1 / `worksheets' {
display " Sheet number `i'"
local shtname`i' `r(worksheet_`i')'
display "loading sheet: `r(worksheet_`i')'"
tempfile ts`i'
save `ts`i'', replace emptyok
foreach f in `xlsx' {
*set trace on
import excel using "$outputs/fb/`f'", sheet("`shtname`i''") firstrow clear
destring value, replace
*set trace on
display "file: `f' and sheet: `shtname`i''"
append using `ts`i''
save `ts`i'',replace
}
export excel using "$outputs/fb/com/combine_hfc_feedback.xlsx", sheet("`shtname`i''") sheetreplace firstrow(var)
}
Related Posts with combining multiple excel file with multiples excel sheets
probit and counterfactual outcomes between groupsHello, I have some issues regarding the estimation of counterfactual treatment effects regression fo…
Multiple line plot of long dataHello all, I’m working with a dataset in the long format. My observations are grouped within ids (i…
Choosing between better estimates and the observation numberHello dear Stata Community, I have a general question about estimators and the number of observatio…
Remove leading "0"Dear all, I have observations entries that look like this: Array I'd like to remove the leading "…
Internal validatiom programHi STATALIST, Following program supposed to give me 100 different MSEs, but it produced 100 same MS…
Subscribe to:
Post Comments (Atom)
0 Response to combining multiple excel file with multiples excel sheets
Post a Comment