Announcement

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

  • While loop

    Hey Statalists,

    haven´t found anything about this topic, so I hope you can help me out.


    If I use a command such as:

    Code:
    while var1 > 0 {
    ....
    ....
    change var1
    }
    Does Stata check whether at least one value of the column var1 is bigger than zero or does it check the first value or..?

    I´m asking because the code I use stopped although some of the values in the column the while command referred to have still been bigger than zero.

  • #2
    I answered it myself - while does check the first observation

    Comment


    • #3
      I rarely write while loops but when I do they often look something like this:

      Code:
      local worktodo = 1
      
      while `worktodo' {
          quietly count if var1 > 0
          if r(N) == 0  local worktodo = 0
          else {
                * code to work more at the problem
          }
      }

      Comment

      Working...
      X