Announcement

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

  • Stata "versus" Mata defaults

    Might someone be so kind as to remind/instruct me of the Stata and Mata defaults that yield these seemingly discordant results?

    Code:
    loc x=1/11
    di 11*`x'==1
    
    mata
     x=1/11
     11*x==1
    end

    Results
    Code:
    . loc x=1/11
    
    . di 11*`x'==1
    0
    
    . 
    . mata
    ------------------------------------------------- mata (type end to exit) -------------------
    :  x=1/11
    
    :  11*x==1
      1
    
    : end
    ---------------------------------------------------------------------------------------------

  • #2
    Consider this further experiment

    Code:
    . scalar x = 1/11
    
    . di (11 * x) == 1
    1
    My take on this:

    1 Local macros are in essence strings. If populated with numeric characters they can be dereferenced and their contents used in numeric calculations, but that's a convenience rather than the main reason for using local macros.

    2. However, as a side-effect local macros can't hold numbers to as much precision as scalars. So, the approximation involved in holding 1/11 as a binary number is biting you when you use locals.

    3. Scalars can hold strings, but in this case the role of holding a number is what is crucial.

    4. Using Mata is equivalent to using scalars here, at least so far as the examples show.

    Not sure where this is documented at the moment....

    Executive summary: This is not so much a matter of Stata or Mata defaults: the limitations of locals are the story.

    Comment

    Working...
    X