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
Why my stata run 'twoway scatter' can not get normal stata pictureHelp! Why my stata run 'twoway scatter' can not get normal stata picture, but get the picture like t…
reghdfe: running a difference in difference model with state FE, year FE and country specific trendsHello, I would like to run a diff-in-diff model with state fixed effects (FE), year FE and states sp…
Help Required with Statsby Dear all, I have a panel dataset with 50 stocks and 43 quarters. Given below is a subset of my data…
Calculating correlation between dummy variables using pwcorrHi, fist of all I was wondering whether pwcorr is okay to use when I would like to calculate the co…
Use estaddHey there, I need your help with the replication of a Regression and the command estadd. The proble…
Subscribe to:
Post Comments (Atom)
0 Response to loops to import excel file and merge
Post a Comment