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
Random effects / POLS / Research QuestionsDear Stata Pros , Being interested in the effect of the share of women in board position on return …
Calculating Risk Ratios and CIsHi, I'm new to STATA 16. Looking for advice on calculating risk ratios and their confidence interva…
Examing and seasonal trends in malaria cases - is OLS appropriate?I am having some issues working with and interpreting seasonal data on malaria cases in country X. I…
Multilevel modelling: 'Intercepts as outcomes model'Hello, I am working with a multilevel binary logistic model. I have read up a lot about how to run a…
areg , robust >>> standard errors are clustered what?Hello could you please help for the following question? I am working for company level panel data bu…
Subscribe to:
Post Comments (Atom)
0 Response to combining multiple excel file with multiples excel sheets
Post a Comment