The reason why you are getting ECHO is on. Is because delayed expansion was not used, which caused the value of%var% and%MyVar% to be inserted before the for command is run, and since they were not defined at the start, empty variables were inserted in. When the echo%MyVar%text.txt was run, it was interpreted as echo text.txt.
![File File](/uploads/1/2/5/6/125611863/988613192.png)
What's happening that Stata has code for looking at your command line before it tries to. See help macro for a terse signal on the `= ' syntax. Title stata.com rename -- Rename variable SyntaxMenuDescriptionRemarks and examplesReferencesAlso see Syntax rename old varname new varname Menu Data > Data utilities > Rename groups of variables Description rename changes the name of existing variable old varname to new varname; the contents of the.
When echo is run without any arguments, it outputs whether echo is on or off, which is what you get in text.txt. To fix the problem, you have to do two things: First, there is something wrong with your second line. There is no space between set and local in setlocal. The second line should be SETLOCAL EnableDelayedExpansion.
Second, to use delayed expansion, you have to replace all%s in each variable with!, like!var! Instead of%var%. End result: @echo ON SETLOCAL EnableDelayedExpansion For%%# in (.) do ( SET var=%%n# Set MyVar=!var! Set MyVar=!MyVar: =!
Echo!MyVar!text.txt ) You actually do not need to use a temporary variable in this case, you can just do SET MyVar=%%n# and skip to set MyVar=!MyVar: =!