Announcement

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

  • Mata: Unexpected End of File

    Hello,

    I'm just learning about Mata so I can use it code OPTIMIZE. I'm stuck because I keep getting "unexpected end of file" errors. Any ideas?

    Code:
    program define mata1
    clear
    
    clear mata
     mata
     void myeval(todo,x, y, g, H)
    {
        y = x
    }
    end
    Output:
    Code:
    . mata1
    note: argument todo unused
    note: argument g unused
    note: argument H unused
    unexpected end of file (end statement missing)
    If I put a second "end" at the bottom of the file I get "command end is unrecognized"

    Thanks.

  • #2
    I'm not sure how to delete a thread, but I found a solution to my problem.

    Comment


    • #3
      Actually still having problems with this. Another example:

      Code:
      program define mata1
      clear
      
      sysuse auto
      mata:
      function linregeval(transmorphic M, real rowvector b,
      real colvector lnf)
      {
      real colvector p1, p2
      real colvector y1
      p1 = moptimize_util_xb(M, b, 1)
      p2 = moptimize_util_xb(M, b, 2)
      y1 = moptimize_util_depvar(M, 1)
      lnf = ln(normalden(y1:-p1, 0, sqrt(p2)))
      }
      M = moptimize_init()
      moptimize_init_evaluator(M, &linregeval())
      moptimize_init_depvar(M, 1, "mpg")
      moptimize_init_eq_indepvars(M, 1, "weight foreign")
      moptimize_init_eq_indepvars(M, 2, "")
      moptimize(M)
      moptimize_result_display(M)
      end
      Code:
      Output:
      
      
      . mata1
      (1978 Automobile Data)
      initial:       f(p) =     -<inf>  (could not be evaluated)
      feasible:      f(p) = -12949.708
      rescale:       f(p) = -243.04355
      rescale eq:    f(p) = -236.58999
      Iteration 0:   f(p) = -236.58999  (not concave)
      Iteration 1:   f(p) = -227.46735  
      Iteration 2:   f(p) = -205.73129  (backed up)
      Iteration 3:   f(p) = -195.72216  
      Iteration 4:   f(p) = -194.20847  
      Iteration 5:   f(p) = -194.18313  
      Iteration 6:   f(p) = -194.18306  
      Iteration 7:   f(p) = -194.18306  
      
                                                      Number of obs     =         74
      
      ------------------------------------------------------------------------------
               mpg |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
      -------------+----------------------------------------------------------------
      eq1          |
            weight |  -.0065879   .0006241   -10.56   0.000     -.007811   -.0053647
           foreign |  -1.650029   1.053958    -1.57   0.117    -3.715749    .4156903
             _cons |    41.6797   2.121197    19.65   0.000     37.52223    45.83717
      -------------+----------------------------------------------------------------
      eq2          |
             _cons |   11.13746   1.830987     6.08   0.000      7.54879    14.72613
      ------------------------------------------------------------------------------
      unexpected end of file (end statement missing)

      Comment


      • #4
        See post #2 in

        https://www.statalist.org/forums/for...-don-t-press-q

        Comment


        • #5
          Thanks, that's helpful. I can get it to run in a do file but not an ado file. I prefer ado, but I'll use do for this.

          Comment


          • #6
            If you have not already done so, read the fine material in
            Code:
            help [M-1] ado
            for advice on using Mata in ado files.

            Comment

            Working...
            X