Hi,
I have hundreds of excel files and I would like to import each of them one by one and save them in Stata format. I put the names of the files in a global and then loop the importing and saving process over each value in the global. I use the following code:
I get the following result and error:
AADA01
invalid 'AADA01'
r(198);
When I use the code without the quotation as follows:
I get the following error:
file C:\Users\39349\Documents\AF\Courses`x'- fu.csv not found
r(601);
What am I doing wrong here?
I have hundreds of excel files and I would like to import each of them one by one and save them in Stata format. I put the names of the files in a global and then loop the importing and saving process over each value in the global. I use the following code:
global c AADA01 AADA05 AADA20 AADA25 AAHA60 AAHA60 AAHA60 AAHA60 AAHA60 AAHF01 AAHF10 AAHN02 AAHN02 AAHN15 AAHN25 AAHN25 AAHN40 AAHN45 AAKN20 AAKN20 AAMN01 ABAN06 ABAN11 ABAN15 ABFF01 ABKF10 ABKF10 ABMM01 ABMM01 ABMM02 ABMM03 ABMM08 ABMM50 ABMM55 ABMM70 ABVA05 AEBF10 AEBF15 AEBF25 AEBF30 AEBN10 AFOA15 AFOA20
foreach x in $c {
di "`x'"
import delimited using "C:\Users\39349\Documents\AF\Courses"`x'"- fu", clear
save "C:\Users\39349\Documents\AF\Courses- Stata"`x'"", replace
}
foreach x in $c {
di "`x'"
import delimited using "C:\Users\39349\Documents\AF\Courses"`x'"- fu", clear
save "C:\Users\39349\Documents\AF\Courses- Stata"`x'"", replace
}
AADA01
invalid 'AADA01'
r(198);
When I use the code without the quotation as follows:
foreach x in $c {
di "`x'"
import delimited using "C:\Users\39349\Documents\AF\Courses\`x'- fu", clear
save "C:\Users\39349\Documents\AF\Courses- Stata\`x'", replace
}
di "`x'"
import delimited using "C:\Users\39349\Documents\AF\Courses\`x'- fu", clear
save "C:\Users\39349\Documents\AF\Courses- Stata\`x'", replace
}
file C:\Users\39349\Documents\AF\Courses`x'- fu.csv not found
r(601);
What am I doing wrong here?
Comment