Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


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

RE: st: beginer's mata function in dofile


From   tashi lama <ltashi32@hotmail.com>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: beginer's mata function in dofile
Date   Wed, 8 Aug 2012 15:22:11 +0000

Thanx...that makes sense although the following do-file seems to contradict(unless I am not seeing something). In the following do-file, the mata function is called prior to it being defined. And it works. 
//begin do-file mata1.do 
clear all 
set obs 10
forvalues i=1/5 {
g bp`i'=runiform()
} 
capture program drop nn
prog nn, rclass
mata: do_trend_var("b", "bp1 bp2 bp3 bp4 bp5")
list 
end 
version 12
mata
void function do_trend_var(string scalar newvarname, string scalar varnames)
{
real matrix Y
real colvector b
real scalar idx
st_view(Y,.,varnames) 
b=(1::rows(Y))
idx=st_addvar("float",newvarname) 
st_store(.,idx,b) 
}
end 
nn

Thanx... 

----------------------------------------
> Date: Wed, 8 Aug 2012 12:40:34 +0200
> Subject: Re: st: beginer's mata function in dofile
> From: klein.daniel.81@googlemail.com
> To: statalist@hsphsun2.harvard.edu
>
> Tashi,
>
> there is nothing I can really add to that statement. The critical
> point is to define/compile the Mata function before you call it. This
> do-file works, without a -program- being defined.
>
> m :
> void myfunc(real scalar x)
> {
> x
> }
> end
>
> loc x 42
> m : myfunc(`x')
>
> Best
> Daniel
>
> --
> The only thing I didn't follow is where you say... it is not necessary
> to define a program that calls mata functions. Could you elaborate on
> that?
> *
> * 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/ 		 	   		  
*
*   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   |   Site index