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

st: re: mata error function name already exists

From   Kit Baum <>
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?

This seems to work:

mata: mata clear
	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


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'

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

Kit Baum, Boston College Economics and DIW Berlin
An Introduction to Modern Econometrics Using Stata:

*   For searches and help try:

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