Statalist


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

st: Mata st_store problem with selectvar (using mm_root)


From   Bob Hammond <robert_hammond@ncsu.edu>
To   statalist@hsphsun2.harvard.edu
Subject   st: Mata st_store problem with selectvar (using mm_root)
Date   Wed, 11 Feb 2009 10:25:26 -0500

All,

I want to store a Mata scalar in my Stata data set using st_store(), but only in certain cases, as determined by selectvar. My reading of the st_data() help file (where st_store() directs you to concerning selectvar) says that the following should work:

clear
cap mata: mata drop myfunc()
set obs 1
gen double rc = .
gen double x = .
mata
   function myfunc(x, a) return(x^2 - a)
   a = 2
   rc = (mm_root(x = .,&myfunc(),0,1,0,1000,a)==0)
   st_store(1,"rc",rc)
   st_store(1,"x",1,x)
end
list

My Stata variable "rc" is equal to one if the mm_root() function has found a valid solution. I only want st_store() to write the solution to the data set when it is valid.

Instead, the program correctly writes the solution to the data set when it is valid (try by changing a to "a = 2/3" above) but generates a "3200 conformability error" when it is invalid (try the program as written above, which generates no valid solution because it looks between 0 and 1 for the square root of 2). Maybe this is a simple error in my reading of how to use selectvar but I have tried it by placing "rc" and, alternatively, by placing 1 (the variable number of "rc") in the third argument of st_store(). Both ways give the same conformability error.

Any thoughts would be appreciated.  Thanks in advance,

Bob
--
------------------------------------------------------------------------
Bob Hammond
Department of Economics
North Carolina State University
Office: (919) 513-2871
Fax: (919) 515-7873
http://www4.ncsu.edu/~rghammon/
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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