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: Error in function evaluator programs with nl


From   "Brian P. Poi" <[email protected]>
To   [email protected]
Subject   Re: st: Error in function evaluator programs with nl
Date   Wed, 28 Mar 2012 12:22:46 -0500

On 03/28/2012 11:32 AM, Guillaume Daudin wrote:

Dear stata list users,

I do not seem to be able to create a function evaluator program. I suppose I am missing something obvious…

Here is the program :

capture program drop nltc_add
program nltc_add
version 11
	syntax varlist (min=4 max=4) if, at(name)
	local prix_trsp21       : word 1 of `varlist'
	local prix_fob1         : word 2 of `varlist'
	local dist1     		: word 3 of `varlist'
	local contig1 			: word 4 of `varlist'

	tempname rho_ice rho_add rho_conti rho_conta
	scalar `rho_ice'=`at'[1,1]
	scalar `rho_add'=`at'[1,2]
	scalar `rho_conti'=`at'[1,3]
	scalar `rho_conta'=`at'[1,4]
	replace `prix_trsp21'= `dist1'^`rho_ice'*`rhoconti'*`contig1'+`dist1'^`rho_add'*`rhoconta'*`contig1'/`prix_fob1' `if'
end

But running :

nl tc_add @ prix_trsp21 prix_fob1 dist1 contig1, parameters(rho_ice rho_add rho_conti rho_conta) initials(rho_ice 0.1 rho_add 0.3 rho_conti 0 rho_conta 0)

gives me a r(198) error:

nltc_add returned 198
verify that nltc_add is a function evaluator program

Thanks in advance for any help !



There are two bugs here.  First, the option to specify initial values is 'initial()', not 'initials()'.  Since -nl- does not accept an 'initials()' option, it passes that option onto your function evaluator program.  But your program does not accept an 'initials()' option, either, so it issues the error message.  -nl- gives you the flexibility to pass options to your evaluator program, but the cost is that -nl- itself cannot determine whether you misspelled one if its options or if you specified an option for your program.

The second issue is that you define the temporary scalars rho_conti and rho_conta, but you refer to rhoconti and rhoconta in your -replace- statement.

When I fix those two bugs, the program works with artificial data.


   -- Brian Poi
   -- [email protected]

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