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
Counting the number of values (that are not missing values)Hello! I want to make a variable based on other variables. The value of the variable would be the n…
Nested or Non nested?I have the following two models. I want to know whether these two models can be considered nested or…
Loop to change MDE and N in pcpanel commandHi. I'm using the pc_simulate command to find a sample size that will give me a power of 80%. I want…
Adding a non-standard row to a summary tableHi there! I'm new to STATA and trying to create a table similar to the below. Specifically, I'm loo…
Clustering Standard ErrorI am working on finding the relationship between FDI inflow and military expenditure. I have panel d…
Subscribe to:
Post Comments (Atom)
0 Response to loops to import excel file and merge
Post a Comment