I learned yesterday that I can use empty string as a placeholder to try 2 specifications: one with a variable and the other without. See the solution here. I have an additional question regarding how to save such different specifications using outreg2.
The output in test.xml is not property formatted due to the empty string of 2nd iteration in macro p.

I understand that it is trivial for this particular example since the output implies which specification is used. However, I want to learn the proper way to be able to display this empty string.
Through some trial and error, I found the problem is because the macro p becomes undefined in the 2nd iteration.
Code:
webuse lifeexp
local p12 popgrowth ""
foreach p in `p12'{
reg lexp gnppc `p'
outreg2 using "test.xml", addtext(popgrowth, `popgrowth')
}
The output in test.xml is not property formatted due to the empty string of 2nd iteration in macro p.
I understand that it is trivial for this particular example since the output implies which specification is used. However, I want to learn the proper way to be able to display this empty string.
Through some trial and error, I found the problem is because the macro p becomes undefined in the 2nd iteration.
Code:
webuse lifeexp
local p12 popgrowth ""
foreach p in `p12'{
reg lexp gnppc `p'
outreg2 using "test.xml", addtext(popgrowth, `popgrowth')
macro list _p
}
