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
Questions about asdoc with option keepHello, everyone! I am using asdoc to report some nested regression tables to Word. For the sake of …
How do I load data in Stata from the internet? I am not able to make -webuse- work...Good morning, I am trying to load from within Stata a file on this website https://www.lisdatacente…
pscoreIs the command pscore present in Stata 16? …
Problems in obtaining the right hand side confidence interval of a regressionHi there, I calculated the abnormal returns of german federal state bonds as well as I plotted them…
psgraphI'm using the psgraph command to generate a propensity score histogram with the binary treatment var…
Subscribe to:
Post Comments (Atom)
0 Response to combining multiple excel file with multiples excel sheets
Post a Comment