Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: st: beginer's mata function in dofile


From   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: beginer's mata function in dofile
Date   Wed, 8 Aug 2012 16:39:33 +0100

No. The hierarchy is that your program -nn- is defined before it is run. That defines the Mata function before that itself is run.

Nick

On 8 Aug 2012, at 16:22, tashi lama <[email protected]> wrote:

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: [email protected]
To: [email protected]

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/
*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index