Announcement

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

  • How to store moptimize() results and use it in another program?

    Hi all,


    I am having trouble storing moptimize results (moptimize_result_coefs(M)) from mata, shown below. It returns a 1*2 row vector, I am able to extract each element, but not sure how to store them.

    I also need to use the returned coefficients in another program. I'd really appreciate any advice you may have!

    mata:
    function minsearch(transmorphic M, real rowvector b, real colvector lnf)
    {
    real colvector p1
    real colvector y1
    p1 = moptimize_util_xb(M, b, 1)
    y1 = moptimize_util_depvar(M, 1)
    lnf = ln(normalden(y11, 0, 2))
    }

    M = moptimize_init()
    moptimize_init_evaluator(M, &minsearch())
    moptimize_init_depvar(M, 1, "y")
    moptimize_init_eq_indepvars(M, 1, "x")
    moptimize(M)
    moptimize_result_coefs(M)
    end

  • #2
    Lei Ma --

    You can save the results to disk as an .mmat file, and then load them as needed. In your case, this would require you to first put the resulting coefficients into matrix:

    Code:
    foo = moptimize_result_coefs(M)
    Then:

    Code:
    mata matsave Foo foo, replace
    (saving foo[1,4])
    file Foo.mmat saved
    and then when you need the coefficients:

    Code:
    mata matuse Foo
    (loading foo[1,4])
    Hope that helps!

    Matthew J. Baker

    Comment

    Working...
    X