[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 <>
Subject   st: Mata st_store problem with selectvar (using mm_root)
Date   Wed, 11 Feb 2009 10:25:26 -0500


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:

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

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 Hammond
Department of Economics
North Carolina State University
Office: (919) 513-2871
Fax: (919) 515-7873
*   For searches and help try:

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