Hi,
I am looping across several files to clean some datasets imported from Excel. I want to match each of my firm names with a mapping table so I can get their ID. However, some firm names have this expression ""&" instead just a normal ampersand, so the match won't perform correctly.
I tried this code:
Now it seems to work for *some* files because the tracer gave me this result when the code was running :
- else if `amper' > 0 {
= else if 232 > 0 {
replace `var' = subinstr(`var', "&", "&", .)
}
However when I try to open the first of my many files (just out of curiosity, because I knew there was a problem like this in the first file)
What did I do wrong here?
I am looping across several files to clean some datasets imported from Excel. I want to match each of my firm names with a mapping table so I can get their ID. However, some firm names have this expression ""&" instead just a normal ampersand, so the match won't perform correctly.
I tried this code:
Code:
foreach si of local site { foreach file in `files_`si'' { foreach var of varlist name* { local amper = strpos(`var[1]', "&") set tr on if `amper' > 0 { replace `var' = subinstr(`var', "&", "&", .) set tr off } tempfile `file'_CLEAN save ``file'_CLEAN' }
- else if `amper' > 0 {
= else if 232 > 0 {
replace `var' = subinstr(`var', "&", "&", .)
}
However when I try to open the first of my many files (just out of curiosity, because I knew there was a problem like this in the first file)
Code:
use `file1_CLEAN', clear dataex name16, count(1)
Code:
* Example generated by -dataex-. For more info, type help dataex clear input str36 name16 "xxxxxxx & xxxxxx" end
Comment