Hi everyone,
I have a folder that contains 26 individual .xlsx files, each named with the name of a country. In a separate folder I have 26 .dta files with named with corresponding country names. I would like to use a loop to import the Excel files and merge in several variables from the corresponding dta file and then save as a new merged file, for each country. I currently have the following code and am getting stuck on the merge file name which I assume has to do with how I'm using the loop indicator in the file path.
When I try with `i', I get the error ".../Merge format `i'.xlsx not found"
with "`i'", I get the error "using required"
and with `"i"', I get the error "too many ')' or ']'"
Any help would be very much appreciated. Thanks.
foreach i in 1/26 {
import excel "C:\...\Merge format\`i'.xlsx", sheet("Labor") firstrow clear
merge 1:1 WP5889 using "C:\...\Merge datasets"`i'".dta", keepusing(P8A P8B P8C)
drop if _merge==2
save `i'_verbatims, replace
}
Related Posts with loops to import excel file and merge
Calculating Standard Deviation with RangestatHey all, I have the following problem. I would like to calculate rolling standard deviation of the …
Combining observations into oneI´m working on a data which has registered repeated observations because there are some observations…
Working on Nested LoopMy data is stored in a panel data format. I want to estimate the ARDL model that accommodates one st…
grc1leg; how to control legend text and marker sizeDear listers I would like to use the grc1leg to produce a figure, housing multiple plots but with on…
Legend for graphs with marker symbol invisibleHello, I am graphing a twoway dot, with two variables. I can´t seem to find a way to add a legend …
Subscribe to:
Post Comments (Atom)
0 Response to loops to import excel file and merge
Post a Comment