Dear Statalist forum,
I am running a loop to open all excel files inside a folder, make calculations and save the data as new excel files in a separate folder. However, I get an error now that my generated variable already exists after first loop, so only the first file is being processed.
I have attempted to use drop preserve/restore and both together but is does not solve my problem.
Can anyone here help me to identify the problem? I am truly grateful for your time
Output:
*Im using Stata 17 on a PC with this code
I am running a loop to open all excel files inside a folder, make calculations and save the data as new excel files in a separate folder. However, I get an error now that my generated variable already exists after first loop, so only the first file is being processed.
I have attempted to use drop preserve/restore and both together but is does not solve my problem.
Can anyone here help me to identify the problem? I am truly grateful for your time
Code:
**Loop with other solution to loop * change path to where the folder with the raw xlsx that we want to change (Folder A) cd $RAW * We will open the excel files from folder A and save the edited excel files in Folder B (export folder) set trace on local xlsx : dir . files "*.xlsx" local xlsx : subinstr local xlsx ".xlsx" "", all foreach f of local xlsx { di "`f'" import excel using `f', firstrow clear preserve *Calculate our variables: * 1)Sensitivity with 95% CI *first we convert Sensitivity back to fraction gen sens = Sensitivity/100 export excel using "$EXPORT\newest_`f'", firstrow(variables) replace drop sens restore }
Code:
variable sens already defined
*Im using Stata 17 on a PC with this code
Comment