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


From   "John Francis" <[email protected]>
To   <[email protected]>
Subject   st: RE: Error 198 in function evaluator program with nl
Date   Tue, 12 Nov 2013 09:45:16 -0600

In debugging function evaluator programs I have found it useful to run the program with trace set to on -- just type "set trace on" before you run the program.  This may allow you to see where the program is having a problem.

John Francis
[email protected]


-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Manuel Flores
Sent: Monday, November 11, 2013 1:12 PM
To: [email protected]
Subject: st: Error 198 in function evaluator program with nl

Dear statalist users,
I'm trying to estimate a LS nonlinear model with the nl command in Stata MP/12.1. I have a gravity model of trade, with almost 300 variables (including country fixed effects), so I need to do it running a FEP. As I'm having troubles with the program I started with a shorter version of the model without the dummies, keeping just 17 independent variables and 18 parameters.
However, I keep getting a 198 error code, and I can't realize where the bugs are.
Thanks in advance for any help!

Here is the program:
------------------------------
capture program drop nlgrav
set trace on
program nlgrav
      version 12
      syntax varlist (min=18 max=18) [aw fw iw] if, at(name)
      local lexp: word 1 of `varlist'
      local v1: word 2 of `varlist'
      local v2: word 3 of `varlist'
  local v3: word 4 of `varlist'
  local v4: word 5 of `varlist'
  local v5: word 6 of `varlist'
  local v6: word 7 of `varlist'
  local v7: word 8 of `varlist'
  local v8: word 9 of `varlist'
  local v9: word 10 of `varlist'
  local v10: word 11 of `varlist'
  local v11: word 12 of `varlist'
  local v12: word 13 of `varlist'
  local v13: word 14 of `varlist'
  local v14: word 15 of `varlist'
  local v15: word 16 of `varlist'
  local v16: word 17 of `varlist'
  local v17: word 18 of `varlist'
      // Retrieve parameters out of at matrix
      tempname b0 b1 b2 b3 b4 b5 b6 b7 b8 b9 b10 b11 b12 b13 b14 b15 delta bun
      scalar `b0' = `at'[1,1]
  scalar `b1' = `at'[1,2]
  scalar `b2' = `at'[1,3]
  scalar `b3' = `at'[1,4]
  scalar `b4' = `at'[1,5]
  scalar `b5' = `at'[1,6]
  scalar `b6' = `at'[1,7]
  scalar `b7' = `at'[1,8]
  scalar `b8' = `at'[1,9]
  scalar `b9' = `at'[1,10]
  scalar `b10' = `at'[1,11]
  scalar `b11' = `at'[1,12]
  scalar `b12' = `at'[1,13]
  scalar `b13' = `at'[1,14]
  scalar `b14' = `at'[1,15]
  scalar `b15' = `at'[1,16]
  scalar `delta' = `at'[1,17]
      scalar `bun' = `at'[1,18]
      // Some temporary variables
      tempvar linterm1 linterm2 linterm3 wterm heckterm
      gen double `linterm1' = (`b0' + `b1'*`v1' + `b2'*`v2' + `b3'*`v3' + `b4'*`v4' + `b5'*`v5') `if'
  summarize `linterm1'
  gen double `linterm2' = (`b6'*`v6' + `b7'*`v7' + `b8'*`v8' + `b9'*`v9' + `b10'*`v10') `if'
  gen double `linterm3' = (`b11'*`v11' + `b12'*`v12' + `b13'*`v13' + `b14'*`v14' + `b15'*`v15') `if'
  gen double `wterm' = ln(exp(exp({`delta'})*`v16')-1) `if'
  gen double `heckterm' = (`bun'*`v17') `if'
  // Compute the first part of the function
  replace `lexp' = (`linterm1' + `linterm2' + `linterm3' + `wterm' +
`heckterm')  `if'
end

-------------------------------
I'm creating a matrix with initial values:

matrix A = J(1, 18, 0)
matrix A[1,1]=10
matrix A[1,2]=1
matrix A[1,17]=1
matrix A[1,18]=1

And running the program with the following syntax:

nl grav @ lexp_posit  ///
  ldistcap ///
  border ///
  island_both ///
  island_to_nonisl ///
  island_fr_nonisl ///
  landlock_both ///
  landl_to_nonldlk     ///
          landl_fr_nonldlk ///
  comleg ///
  comlang_off ///
  from_heg_to_col ///
  from_col_to_heg ///
  comcur ///
  rta ///
  rel_coinc ///
  z_bar_hat ///
  eta_hat2  ///
   , parameters(b0 b1 b2 b3 b4 b5 b6 b7 b8 b9 b10 b11 b12 b13 b14 b15 delta bun) at(A)


Best,
Manuel Flores
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/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/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index