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]

st: RE: RE: RE: nl @ within ado


From   Nick Cox <n.j.cox@durham.ac.uk>
To   "'statalist@hsphsun2.harvard.edu'" <statalist@hsphsun2.harvard.edu>
Subject   st: RE: RE: RE: nl @ within ado
Date   Tue, 26 Oct 2010 12:48:54 +0100

Quite. Another point is that this is usually a feature: -nl- was set up so that it calls a program in a separate file, which is often very short and where user-written, as often, needs relatively little programming skill. The alternative of requiring users to edit -nl-, part of the official code, would be totally undesirable from a Stata point of view. 

The same practice applies to -egen-, as well as -ml-, already mentioned. 

Nick 
n.j.cox@durham.ac.uk 

Keith Dear

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). 

Nick Cox

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

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/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index