Announcement

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

  • math function in mata

    Hi, a simple question

    I need to calculate the inverse cumulative standard normal distribution in a column vector.

    in Stata, would be:

    Code:
    . di invnormal(0.18)
    -.91536509
    
    . di invnormal(0.09)
    -1.340755
    however , I could not find a equivalent:

    Code:
    . mata
    ------------------------------------------------- mata (type end to exit) --------------------------------------------------------------------------------------------------------------
    
    : a=(0.18\0.09)
    
    : a
             1
        +-------+
      1 |  .18  |
      2 |  .09  |
        +-------+
    
    : end
    I am expecting:

    Code:
    : a
               1       2
        +-----------------+
      1 |    .18    -.91  |
      2 |    .09   -1.34  |
        +-----------------+
    Is iterating with
    Code:
    :stata("....")
    the only way to go ?

  • #2
    No, to get what you want try:

    Code:
    mata:
    
    p = 0.18 \ 0.09
    p, invnormal(p)
    
    end
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      thanks, Maarten, so I assume that all Stata's math function can be such easily applied in Mata environment.

      Comment


      • #4
        The output of
        Code:
        help m4_intro
        links to descriptions of all the functions available in the Mata environment.

        Comment


        • #5
          thanks Willian and Maarten,

          following up on the subject, I was wondering whether any mata function is able to returns the CUMULATIVE normal distribution for a specified mean and standard deviation.

          Excel has NORM.DIST function and I am still avoid using class Quadrature().

          AFAIK normal and normalden does not provide CUMULATIVE probability.

          Code:
          : normalden(0,0,1)
            .3989422804
          Area (probability) should be 0.5.

          Comment


          • #6
            Code:
            : normal(0)
              .5
            Note that if you want the cumulative value of the N(μ,σ2) distribution at x, you need to translate the distribution to the standard N(0,1) normal distribution.
            Code:
            normal((x-μ)/σ)

            Comment


            • #7
              perfect!

              Comment

              Working...
              X