Announcement

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

  • Function arguments defined "on the fly"

    This may be well known to Mata veterans but I stumbled upon this earlier today and thought I'd share. I'm not sure how useful this would be in batch programming (maybe it saves one line of code) but it could be a time saver in interactive Mata (which is where I stumbled on it).

    Code:
    mata
    
    rseed(2345)
    
    round(y=runiform(1,3),.01)
    round(y,.01)
    y
    
    x=2
    exp(z=3*x+5)
    exp(z)
    
    end
    Results:

    Code:
    :
    : rseed(2345)
    
    :
    : round(y=runiform(1,3),.01)
             1     2     3
        +-------------------+
      1 |  .28   .14   .17  |
        +-------------------+
    
    : round(y,.01)
             1     2     3
        +-------------------+
      1 |  .28   .14   .17  |
        +-------------------+
    
    : y
                     1             2             3
        +-------------------------------------------+
      1 |  .2763897781   .1392858568   .1685803268  |
        +-------------------------------------------+
    
    :
    : x=2
    
    : exp(z=3*x+5)
      59874.14172
    
    : exp(z)
      59874.14172
Working...
X