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
R2 for xtnbreg modelHello everyone, i am currently analyzing a count variable with the -xtnbreg- command. This command …
Dumitrescu & Hurlin (2012) Granger non-causality testHello Dears, I am trying to see the granger causality between government revenue and government spen…
Esttab: Store value of matrix and display in tex-tableDear All, I am encountering the following issue. I want to compute a mean after a regression with t…
Displaying Significance Stars in combined summary and correlations tableDear Forum, i merged my correlations and summary statistics to one table via the below code (thanks…
Missing valuesHello, fellow stata lovers! I am working on my thesis and have a dataset from the Enterprise Survey…
Subscribe to:
Post Comments (Atom)
0 Response to combining multiple excel file with multiples excel sheets
Post a Comment