Announcement

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

  • Using loop for tabout command

    I am running the following command:

    Code:
    foreach var of varlist ` Age - Region Smoking Alcohol ' {
     
    tabout   `variable' using test.txt, append
    
    }
    but getting an error:

    Code:
    varlist required
    r(100);
    Same thing is happening when using the tabulate command alone:

    foreach var of varlist ` Age - Region Smoking Alcohol ' {
    tabulate `var'
    }

    Can anyone please help detect the source of the error?
    Last edited by Sonnen Blume; 25 Apr 2019, 15:40.

  • #2
    Code:
    foreach var of varlist Age - Region Smoking Alcohol {
    tabout `var' using test.txt, append
    }

    Comment


    • #3
      In your first example there are two problems, one is that by enclosing your varlist in single quotes you are treating it as a previously defined macro, which it is not. The other is that you refer to the local macro variable in your loop when what you have specified is var. Try this:

      Code:
      foreach var of varlist Age - Region Smoking Alcohol {
          tabout `var' using test.txt, append
      }

      Comment


      • #4
        Originally posted by Sarah Edgington View Post
        In your first example there are two problems, one is that by enclosing your varlist in single quotes you are treating it as a previously defined macro, which it is not. The other is that you refer to the local macro variable in your loop when what you have specified is var. Try this:

        Code:
        foreach var of varlist Age - Region Smoking Alcohol {
        tabout `var' using test.txt, append
        }
        Thanks indeed for the clarification.

        Comment

        Working...
        X