Hello everyone! I'm facing a little difficulty using the strtrim() command here. As always, I looked on the forum to search for possible answers but none of them seemed convincing.

I'm trying to do a simple change here, that is, to remove all leading spaces in one observation using the command strtrim() function in a loop across several of my variables. However, for a reason I don't know, the code just won't work for all of them. Please consider this simple example :

Code:
* Example generated by -dataex-. For more info, type help dataex
clear
input str16 FW str22 FX str33 FY
" [xxx]" "   [yyy]" " [zzz]"
end
As you can see, all 3 variables have leading spaces that I wish to remove. However, the code :

Code:
foreach var of varlist FW-FY {
replace `var' = strtrim(`var')
}
yields

Code:
* Example generated by -dataex-. For more info, type help dataex
clear
input str16 FW str22 FX str33 FY
"[xxx]" "   [yyy]" "[zzz]"
end
the second one didn't change. I noticed that other later operations I also included in the loop such as subinstr do not work on the FX variable as well as many others in my dataset. I suspected that there might be other types of "blank space" characters, and indeed, after looking at -chartab- (from SSC), I tried including:

Code:
foreach var of varlist FW-FY {
replace `var' = strtrim(`var')
replace `var' = subinstr(`var', uchar(160), "", .)
}
But nothing changes too. Could you please tell me what's wrong here please ? It would help me a lot