Statalist


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

st: re: mata error function name already exists


From   Kit Baum <baum@bc.edu>
To   statalist@hsphsun2.harvard.edu
Subject   st: re: mata error function name already exists
Date   Thu, 11 Dec 2008 08:26:12 -0500

< >
Carl said

I am trying to bootstrap a gmm estimator with generated explanatory variables defined by the following mata function
...
When it runs I get the error gmmrsk() already exists r(3000).
With stata programs I know you avoid this with the capture program drop prefix.
Is there an analogous mata prefix or am I doing something else wrong?
Thanks.



This seems to work:

----------------------------
mata: mata clear
mata:
	mata set matastrict on
void gmmrsk(string scalar yname, string scalar hname, string scalar xname)
{
	real colvector y, r, coeff, c1, c2, c
	real matrix h, x, b11, b12, b21, b22, b
	real scalar samvar, lambda
	
	y = st_data(.,yname)
	h = st_data(.,tokens(hname))
	x = st_data(., tokens(xname))
	r = h[.,1] \ h[.,2]
	samvar = variance(r)
	lambda = 0.526/samvar

// construct matrices for parameter estimation
// pieces are constructed and put together
// coefficient estimated
b11 = h'h
b12 = x'x
b21 = lambda*(x'h)
b22 = x'x
c1 = h'y
c2 = x'y
c = c1 \ c2
b = (b11 , b12) \ (b21, b22)
coeff = luinv(b)*c

// return coefficient to stata to bootstrap standard errors
st_numscalar("b1",coeff[1,1])
st_numscalar("b2",coeff[2,1])
st_numscalar("b3",coeff[3,1])
st_numscalar("b4",coeff[4,1])

}
end

capt prog drop carl
prog def carl, rclass
mata: gmmrsk("price","weight mpg","turn length")
forv i=1/4 {
	ret scalar b`i' = b`i'
}
end

bootstrap b1=b1 b2=b2 b3=b3 b4=b4: carl
----------------------


Kit Baum, Boston College Economics and DIW Berlin
http://ideas.repec.org/e/pba1.html
An Introduction to Modern Econometrics Using Stata:
http://www.stata-press.com/books/imeus.html


*
*   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