Announcement

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

  • stata() in Mata loops

    Hello everyone,

    I nee to use some stata commands inside a mata loop and it seems not to work.

    For example if I run:

    Code:
    clear mata
    mata
    
    k=2
    stata("timer on 1")
    stata("sleep " + strofreal(k) + "000")
    stata("timer off 1")
    stata("timer list 1")
    stata("timer clear")
    
    end
    the code executes without problems. But if I use a loop with the same expretions:

    Code:
    clear mata
    mata
    
    for (k=1; 5<=k; k++) {
    stata("timer on 1")
    stata("sleep " + strofreal(k) + "000")
    stata("timer off 1")
    stata("timer list 1")
    stata("timer clear")
    }
    end
    the code executes seemingly without problems too and does not show any error code.
    But it does not wait for even one second.

    Do I miss something or is there an other way to use stata() inside a mata loop?

  • #2
    Dennis, try the following in your loop:
    Code:
    for (k=1; k<=5; k++ ) {
    ...
    }

    Comment


    • #3
      Alberto, thank you for replying. Unfortunately, your post does not help me to understand why my code is not working.

      Comment


      • #4
        Compare your 5 <= k with Alberto's k <= 5. When you start with k=1 the condition 5 <= 1 is false and the loop terminates immediately.

        Comment


        • #5
          Now it works like it should.
          Thank you Alberto and German Rodriguez!

          Comment

          Working...
          X