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]

st: RE: RE: nl @ within ado


From   "Keith Dear" <[email protected]>
To   <[email protected]>
Subject   st: RE: RE: nl @ within ado
Date   Tue, 26 Oct 2010 10:34:26 +1100

Nick,
No problem at all -- except that it didn't work (that's what I meant by
"Stata wasn't fooled": sorry for being cryptic).

======== mymodel.ado
run nlmyfit.do	// try defining the required program externally
prog mymodel
...
nl myfit @ y x, param(...) init(...)
...
end
======== nlmyfit.do
prog nlmyfit
...
end
====================
But -prog list- STILL shows mymodel.nlmyfit, and there is still no
program called just nlmyfit, which nl requires.

However I have just tried (what I suppose should have been obvious)
defining nlmyfit in nlmyfit.ado instead of in nlmyfit.do, and allowing
Stata to find it when needed instead of loading it explicitly as above
-- and that now works.

It would be good if -help nl- could mention that when calling -nl- from
a user-written ado file, 
the function evaluator program MUST be defined in a separate ado file,
not within (or from within) the primary one.



This is the situation (here "B" is playing the role of -nl-):
======== A.ado
prog A
di "A"
C
B
end

prog C
di "C"
end
======== B.ado
prog B
di "B"
C
end
============

. discard
. A
A
C
B
unrecognized command:  C
r(199);

We are told that when faced with the command A, Stata (not finding said
command) executes A.ado then tries again. So why is program C not
defined along with A? Answer: because it is silently renamed "A.C", and
is not available except directly to A. "Stata does not find this
confusing and neither should you." (U18.11.4). 
kd



-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Nick Cox
Sent: Monday, 25 October 2010 11:16 PM
To: '[email protected]'
Subject: st: RE: nl @ within ado

Conversely, why it is a problem that a separate file is needed? For
example, packages based on -ml- are distributed as sets of files. 

Nick 
[email protected] 

Keith Dear

I am trying to build an ado file to fit a certain nonlinear model using
the function evaluator version of nl.
This requires defining a subsidiary program whose name must begin with
'nl'. So I wrote something like this:

======== mymodel.ado
prog mymodel
...
nl myfit @ y x, param(...) init(...)
...
end

prog nlmyfit
...
end
====================

This doesn't work because, being a subprogram of mymodel, the program
nlmyfit is actually named mymodel.nlmyfit, and so nl doesn't find it. If
I move the definition of nlmyfit to the calling do-file then the whole
thing works, but that defeats the purpose of writing an ado file at all.

Is there a way to define a program within an ado file but NOT have it
named as a subprogram?
(I tried putting nlmyfit in a separate file and running it from within
mymodel.ado, but Stata wasn't fooled.)
Or any other solution?

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