Announcement

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

  • Variable Names in Foreach loop

    Hi All
    I am using foreach loop in a code and write results to a file. How can I write the variable names from the foreach loop. Currently, I am able to use `: var lab `v'' for retrieving the variable labels , but cannot find a way to send variable names to the file instead of their labels. Any help would be appreciated.
    Regards
    --------------------------------------------------
    Attaullah Shah, PhD.
    Professor of Finance, Institute of Management Sciences Peshawar, Pakistan
    FinTechProfessor.com
    https://asdocx.com
    Check out my asdoc program, which sends outputs to MS Word.
    For more flexibility, consider using asdocx which can send Stata outputs to MS Word, Excel, LaTeX, or HTML.

  • #2
    Please post your code (the foreach loop and the save/write command) and explain what you would like to have in the end in more detail; that will make it easier to advise you

    Comment


    • #3
      foreach v of varlist PROF SIZE LEV{
      sum `var'
      ...
      ...
      ...
      file write h "\pard\intbl\ql {`:var label `v''}\cell "
      {
      }
      I want the variable names PROF SIZE LEV instead of their labels in the file writing
      Regards
      --------------------------------------------------
      Attaullah Shah, PhD.
      Professor of Finance, Institute of Management Sciences Peshawar, Pakistan
      FinTechProfessor.com
      https://asdocx.com
      Check out my asdoc program, which sends outputs to MS Word.
      For more flexibility, consider using asdocx which can send Stata outputs to MS Word, Excel, LaTeX, or HTML.

      Comment


      • #4
        I was experimenting, the following worked for me
        file write h "\pard\intbl\ql {`:dis "`v'"'}\cell "
        , Thanks for your consideration.
        Regards
        --------------------------------------------------
        Attaullah Shah, PhD.
        Professor of Finance, Institute of Management Sciences Peshawar, Pakistan
        FinTechProfessor.com
        https://asdocx.com
        Check out my asdoc program, which sends outputs to MS Word.
        For more flexibility, consider using asdocx which can send Stata outputs to MS Word, Excel, LaTeX, or HTML.

        Comment


        • #5
          To spell out what appears to be the problem, the name in the loop declaration and that inside the loop should match. You declared -v- but used -var-.

          Comment

          Working...
          X