Announcement

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

  • Best way to simulate an inverse?

    I need to simulate the inverse of a function that has no closed-form solution, and I was wondering if there's a clean way to do that in Stata. So far I've been doing something along the lines of:
    Code:
    set obs 1000
    gen x = _n
    gen y = expression in terms of x
    and then just matching values of y to values in my data, which is not at all practical for large datasets. I know Stata can graph continuous functions using twoway function, but is there a way to exploit this ability to back out values of x from a given value of the function?

  • #2
    This sounds like a case for interpolating x as a function of y. In practice, I would often use cubic splines. mipolate (SSC) is a wrapper for the inbuilt Mata functions.

    Comment


    • #3
      You can go more fancy by choosing where to place the knots in some close to optimal manner. I did that with some Mata code in margdistfit. The source code is available on SSC as ancillary files.
      ---------------------------------
      Maarten L. Buis
      University of Konstanz
      Department of history and sociology
      box 40
      78457 Konstanz
      Germany
      http://www.maartenbuis.nl
      ---------------------------------

      Comment

      Working...
      X