Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: RE: query regarding mata

From   "Nick Cox" <>
To   <>
Subject   st: RE: query regarding mata
Date   Sun, 11 Apr 2010 18:59:13 +0100

This doesn't look complete. 

-mreldif(,)- will surely complain if -lastv- is not defined when it is

Is there more code upstream of this? 

Conversely, my guess is that -lastv- has been defined previously, but is
of different dimensions: hence the conformability message. 

You might try some initialisation of -lastv- to 1,1,1,1,1 before
entering the loop. 


Abhimanyu Arora

I am trying to use mata to find the fixed point of a contraction
Basically I have 5 non-linear equations in 5 variables (all explicitly
expressed in terms of the others). Since I wasn't successful with
'optimize', I tried to use the following idea-start with a vector of
and put the elements of vector of unknowns into the RHS of the equations
till convergence is achieved (updated value 'almost equal' to previous

Following is my code and output:

clear mata

. mata
------------------------------------------------- mata (type end to
: real vector fpt(real scalar x,real scalar y) \\x and y are the
of the equations 
> {
> v=0,0,0,0,0
> while (mreldif(v,lastv)<10^(-6)) {
> lastv=v
> v[1,1]=0.5775+ln(exp(x+0.9*v[1,2])+exp(y+0.9*v[1,1]))
> v[1,2]=0.5775+ln(exp(2*x+0.9*v[1,3])+exp(y+0.9*v[1,1]))
> v[1,3]=0.5775+ln(exp(3*x+0.9*v[1,4])+exp(y+0.9*v[1,1]))
> v[1,4]=0.5775+ln(exp(4*x+0.9*v[1,5])+exp(y+0.9*v[1,1]))
> v[1,5]=0.5775+ln(exp(5*x+0.9*v[1,5])+exp(y+0.9*v[1,1]))
> }
> return(lastv)
> }
note: variable lastv may be used before set

: fpt(2,3)
               mreldif():  3200  conformability error
                   fpt():     -  function returned error
                 <istmt>:     -  function returned error

: end

The error code indicates that there is some operation that is not
with the matrices involved. It would be nice if you could point out the

*   For searches and help try:

© Copyright 1996–2017 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index