Announcement

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

  • Creating a loop for univariate logistic regression of multiple variables

    What is the proper syntax? I tried the following code but get invalid name on last entry.


    local predictorvar "var1 var2 var3 var4 var5 var6"
    foreach p of local predictorvar {
    logit outcome 'p'
    }

  • #2
    Hi Edsel,

    In my opinion, I think you should use the following code
    Code:
    foreach x of varlist var1 var2 var3 var4 var5 var6 {
    logit outcome `x'
    }
    *
    or you should use
    Code:
    foreach x of varlist var1-var6 {
    only if you have consecutive variables from var1 to var6
    Hope it helps!
    Last edited by Thong Nguyen; 27 Dec 2016, 19:26.

    Comment


    • #3
      Originally posted by Edsel Ing View Post
      What is the proper syntax? I tried the following code but get invalid name on last entry.


      local predictorvar "var1 var2 var3 var4 var5 var6"
      foreach p of local predictorvar {
      logit outcome 'p'
      }
      Change
      Code:
      logit outcome 'p'
      to
      Code:
      logit outcome `p'
      and it will then work. The ` character is called "grave accent" or "backtick" in English.

      (The advice that Thong gives is the way that I, too, recommend, by the way.)

      Comment


      • #4
        Thank you very much Thong and Joseph. Much appreciated.
        Is the backtick to the left of the numeral 1?

        Comment

        Working...
        X