Hey Statalist Community,
Apologies for all the code snippets, but I figured the best way for me to explain the issue and my desired outcome is to provide a reproducible example. I appreciate your help.
Version 13.1
OS: Windows 7 Enterprise
To reproduce the issue, we do not need to execute this first snippet of code. This code, which I shall call Code 01, is only necessary for reference purposes. Consider the following code saved to the working directory as duties.do:
We do need to execute this snippet of code, which I shall refer to as Code 02. Consider the following code:
Upon execution of Code 02, we receive Result 01:
There are two issues:
and simply reproduce the line as it is written?
Thank you
Apologies for all the code snippets, but I figured the best way for me to explain the issue and my desired outcome is to provide a reproducible example. I appreciate your help.
Version 13.1
OS: Windows 7 Enterprise
To reproduce the issue, we do not need to execute this first snippet of code. This code, which I shall call Code 01, is only necessary for reference purposes. Consider the following code saved to the working directory as duties.do:
Code:
// ----- Example 01 ----- // foreach x of global duties { replace DutyType`x' = "A" if NAV1`x' != "" replace AV1`x' = NAV1`x' if DutyType`x' == "A" replace NAV1`x' = "" if DutyType`x' == "A" } // ----- Example 02 ----- // foreach x of local vars { replace `x' = subinstr(`x',"'","",.) }
Code:
file open duties using duties.do, read file read duties line while r(eof) == 0 { display `"`line'"' file read duties line } file close duties
Code:
. file open duties using duties.do, read . file read duties line . . while r(eof) == 0 { 2. display `"`line'"' 3. file read duties line 4. } // ----- Example 01 ----- // foreach x of global duties { replace DutyType = "A" if NAV1 != "" replace AV1 = NAV1 if DutyType == "A" replace NAV1 = "" if DutyType == "A" } // ----- Example 02 ----- // foreach x of local vars { replace = subinstr(,,,.)' invalid name r(198); end of do-file r(198); .
- In no case do we have `x' reproduced in the display. I realize that Stata is treating `x' as a local macro and substituting the undefined value into the displayed value, but I do not want Stata to do that.
- In Example 02 of Code Result 01, the subinstr(`x',"'","",.) portion is also being interpreted by Stata. I realize that I can fix this issue by using compound-compound double quotes in Code 02, but that results in most lines beginning with `" and ending with "', which I also do not want.
Code:
display `"`line'"'
Thank you