Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: st_subview() in Mata


From   "William Gould, StataCorp LP" <[email protected]>
To   [email protected]
Subject   Re: st: st_subview() in Mata
Date   Wed, 15 Aug 2007 10:41:53 -0500

I previously responded on the list to Nguyen Cong Minh <[email protected]>,
who wrote, 

>   I used some Mata functions, and used st_view() to get the matrix from
>   data, then use st_subview() to get a submatrix from that matrix.
>
>   ------ Mata code -------
>
>    real matrix V, Yall, Xall
>    neq = st_local("neqn")
>    st_view(V,., tokens(varname))
>    st_subview(Yall,V,.,(1\neq))
>    st_subview(Xall,V,.,(neq+1\cols(V)))
>    
>    It reported the error:
>                 mysub():  3250  type mismatch
>                 <istmt>:     -  function returned error

I said, "I wonder if the error is where Nguyen thinks it is because I see
nothing incorrect in the part of the program quoted," and then I went on to
suggest how Nguyen might track down the error.

Since then, Nick Cox privately wrote me and said, "-st_local()- returns a
string".

Which is to say, in the code above, variable neq is a string variable, 
so in the st_subview calls, (1\neq) and (neg+q\cols(V)) are type 
mismatches.  The fix is to change 

>    neq = st_local("neqn")

to read 

     neq = strtoreal(st_local("neqn"))

That way, neq will be a real rather than a string variable.

-- Bill
[email protected]

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index