Statalist


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

Re: st: mata error function name already exists


From   "Stas Kolenikov" <[email protected]>
To   [email protected]
Subject   Re: st: mata error function name already exists
Date   Thu, 11 Dec 2008 09:03:23 -0600

You can

cap mata : mata drop whatever()

Not that this is a terribly elegant solution but it does work. You can
also start your program with -mata clear-.

On 12/10/08, Carl Nelson <[email protected]> wrote:
> I am trying to bootstrap a gmm estimator with generated explanatory variables defined by the following mata function
>  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
>
>  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.
>
>  Carl Nelson
>
>  *
>  *   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/
>


-- 
Stas Kolenikov, also found at http://stas.kolenikov.name
Small print: I use this email account for mailing lists only.
*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index