Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to display an empty string in outreg2

    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.

    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.

    Click image for larger version

Name:	Screenshot 2022-07-12 at 3.11.56 PM.png
Views:	1
Size:	47.8 KB
ID:	1673277



    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
    
    }
Working...
X