Announcement

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

  • creating frames in a loop (using input...end) triggers the 'Break' message - bug?

    Hello,
    I am trying to figure out if the following code that creates frames in a loop (using input...end) triggers the 'Break' message because it is a bug or it is supposed not to work. It would be useful if it worked. Thanks in advance for comments.

    clear
    frames reset
    mkf mytab
    frame mytab {
    input var1
    1
    end // this works OK
    }

    forval i=1/2 {
    mkf mytab_`i'
    frame mytab_`i' {
    input var1
    1
    end // here is where the 'Break' message shows [r(1)]
    }
    }

  • #2
    Hello Filip Sosenko. After tinkering around with your example, I suspect that input-end within a forvalues loop is causing a problem for some reason. E.g., this worked for me:

    Code:
    * This works
    clear *
    frames reset
    local a = 1
    local b = 2
    mkf mytab_`a'
    frame change mytab_`a'
    pwf
    input var1
    1
    end // here is where the 'Break' message shows [r(1)]
    list
    
    mkf mytab_`b'
    frame change mytab_`b'
    pwf
    input var1
    1
    end // here is where the 'Break' message shows [r(1)]
    list
    frames dir
    So the problem is not using a local macro in a frame name. But the following did not work:

    Code:
    . * This does not work
    . clear *
    
    . frames reset
    
    . forvalues i = 1/1 {
      2.  mkf mytab_`i'
      3.  frame change mytab_`i'
      4.  pwf
      5.  input var1
      6.  1
      7.  end // here is where the 'Break' message shows [r(1)]
    --Break--
    r(1);
    
    end of do-file
    
    --Break--
    r(1);
    But this does work, at least in the sense that it produces the result you seemed to be aiming for with your example. Whether it works in the larger context of what you really want to do, I don't know!

    Code:
    * This works  
    clear *
    frames reset
    forvalues i = 1/2 {
     mkf mytab_`i'
     frame change mytab_`i'
     pwf
     set obs 1
     generate byte v1 = _n
     list
    }
    frames dir
    HTH.



    --
    Bruce Weaver
    Email: [email protected]
    Version: Stata/MP 19.5 (Windows)

    Comment


    • #3
      Many thanks Bruce Weaver . I have resorted ot using 'set obs' instead of 'input'. There is more code to write this way but it seems that I can't do anything about that. Best wishes, Filip

      Comment

      Working...
      X