Announcement

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

  • Numerical evaluation of integrals in Mata

    Dear all,

    Is there a Mata equivalent to Stata's -integ-? Alternatively, which combination of Mata commands and functions do you think could be used to numerically evaluate integrals of one-argument functions?

    Thanks in advance,
    Charles

  • #2
    Ben Jann's -moremata- bundle of Mata functions includes a -mm_integrate()- function which might be your friend here.

    ssc describe moremata

    Philippe

    Comment


    • #3
      Many thanks Philippe. Seems to be just what I need.

      Comment


      • #4
        In fact -mm_integrate()- needs a closed-form function, whereas -integ- works by interpolating individual (x,y) points. So to use -mm_integrate()- when you start with individual points, it seems that you need to construct the function first.
        Last edited by Charles Vellutini; 06 May 2014, 07:48.

        Comment


        • #5
          One option would be to use the official Matat function spline3() for interpolation. I don't think you can feed the cubic spline returned by that function to mm_integrate(). However, a cubic spline is just a series of cubic functions, so the integrations should not be hard. You would need to look up how exactly the spline returned by spline3() is parameterised, but all that is doable.
          ---------------------------------
          Maarten L. Buis
          University of Konstanz
          Department of history and sociology
          box 40
          78457 Konstanz
          Germany
          http://www.maartenbuis.nl
          ---------------------------------

          Comment


          • #6
            Thanks Maarten! Yes, I think that could work. Alternatively, it does not seem that hard to code numerical approximations of one-dimensional integrals directly in Mata. See for example http://en.wikipedia.org/wiki/Numerical_integration. The affine method is straightforward - I did it, seems to work ok. Simson's methods are more involved and I haven't tried them. Maybe your suggestion to use -spline3()- is a better one. I will experiment further and report what I found.

            Comment

            Working...
            X