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: Could someone help me with my nl evaluation program? I update my program.


From   张志强 <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: Could someone help me with my nl evaluation program? I update my program.
Date   Sat, 1 Feb 2014 00:46:55 +0800

Dear Nick
Thank you for your advices. My naive code for 31 region code are as follows:
capture program drop nlwage3
program nlwage3
 version 12
 syntax varlist(min=33 max=33) if, at(name)
 local lnwage : word 1 of `varlist'
 local income : word 2 of `varlist'
 local dist1: word 3 of `varlist'
 local dist2: word 4 of `varlist'
 local dist3:word 5 of `varlist'
 local dist4: word 6 of `varlist'
 local dist5: word 7 of `varlist'
 local dist6: word 8 of `varlist'
 local dist7: word 9 of `varlist'
 local dist8: word 10 of `varlist'
 local dist9: word 11 of `varlist'
 local dist10: word 12 of `varlist'
local dist11: word 13 of `varlist'
local dist12: word 14 of `varlist'
local dist13: word 15 of `varlist'
local dist14: word 16 of `varlist'
local dist15: word 17 of `varlist'
local dist16: word 18 of `varlist'
local dist17: word 17 of `varlist'
local dist18: word 20 of `varlist'
local dist19: word 21 of `varlist'
local dist20: word 22 of `varlist'
local dist21: word 23 of `varlist'
local dist22: word 24 of `varlist'
local dist23: word 25 of `varlist'
local dist24: word 26 of `varlist'
local dist25: word 27 of `varlist'
local dist26: word 28 of `varlist'
local dist27: word 29 of `varlist'
local dist28: word 30 of `varlist'
local dist29: word 31 of `varlist'
local dist30: word 32 of `varlist'
local dist31: word 33 of `varlist'



 tempname k0 k1 k2
 scalar `k0' = `at'[1, 1]
 scalar `k1' = `at'[1, 2]
 scalar `k2' = `at'[1, 3]
 tempvar eterm
 gen double `eterm'=`income'*exp(-1*`k2'*`dist1') ///
  +`income'*exp(-1*`k2'*`dist2') ///
+`income'*exp(-1*`k2'*`dist3') ///
+`income'*exp(-1*`k2'*`dist4') ///
+`income'*exp(-1*`k2'*`dist5') ///
+`income'*exp(-1*`k2'*`dist6') ///
     +`income'*exp(-1*`k2'*`dist7') ///
+`income'*exp(-1*`k2'*`dist8') ///
+`income'*exp(-1*`k2'*`dist9') ///
+`income'*exp(-1*`k2'*`dist10') ///
+`income'*exp(-1*`k2'*`dist11') ///
+`income'*exp(-1*`k2'*`dist12') ///
+`income'*exp(-1*`k2'*`dist13') ///
+`income'*exp(-1*`k2'*`dist14') ///
+`income'*exp(-1*`k2'*`dist15') ///
+`income'*exp(-1*`k2'*`dist16') ///
+`income'*exp(-1*`k2'*`dist17') ///
+`income'*exp(-1*`k2'*`dist18') ///
+`income'*exp(-1*`k2'*`dist19') ///
+`income'*exp(-1*`k2'*`dist20') ///
+`income'*exp(-1*`k2'*`dist21') ///
+`income'*exp(-1*`k2'*`dist22') ///
+`income'*exp(-1*`k2'*`dist23') ///
+`income'*exp(-1*`k2'*`dist24') ///
+`income'*exp(-1*`k2'*`dist25') ///
+`income'*exp(-1*`k2'*`dist26') ///
+`income'*exp(-1*`k2'*`dist27') ///
    +`income'*exp(-1*`k2'*`dist28') ///
+`income'*exp(-1*`k2'*`dist29') ///
+`income'*exp(-1*`k2'*`dist30') ///
 +`income'*exp(-1*`k2'*`dist31')  `if'

 replace `lnwage' = `k0' +`k1'*ln(`eterm') `if'
 end
nl wage3 @ lnwage income dist1 dist2 dist3 dist4 dist5 dist6 dist7
dist8 dist9 dist10 dist11 dist12 dist13 dist14 dist15 dist16 dist17
dist18 dist19 dist20  dist21 dist22 dist23 dist24  dist25 dist26
dist27 dist28 dist29 dist30 dist31     , parameters(k0 k1 k2 )
initial(k0 10 k1 0.34 k2 0.02)

this code return error
nlwage3 returned 199
verify that nlwage3 is a function evaluator program

the problem is that if I reduce the dist variables to 20, this code
working very well.
Does that mean the initial value of my nl program is wrong if I
increase the  dist variables?
Is my program is suitable for estimate the summation over variables equation?
Is there some method to guess the initial values for converge?
I sincerely hope that you can help me!

Zhiqiangzhang

2014-01-31 Nick Cox <[email protected]>:
> "did not work" is difficult to evaluate here. You don't show the code
> you used or explain how it did not work, so hoping for good advice is
> optimistic. Macro length is unlikely to be an issue providing that you
> define your macros appropriately.
>
> What you may be experiencing is just that more complicated models with
> more adjustable parameters are typically (much) more difficult to fit.
> Nonlinear least squares is beautifully attractive when it works
> directly, but it may need very good guesses at parameter values to
> converge well even when the model is suitable.
>
> Nick
> [email protected]
>
> On 31 January 2014 13:37, 张志强 <[email protected]> wrote:
>> Thanks Scott.
>> My program is working well if the dyadic of individual distance is
>> smaller than 20. is there a limitation for local macro number in nl
>> command in stata ?
>> I mean if the dist variables is larger than 20, my nl command did not work.
>> I sincerely hope that you can help me!
>>
>>
>>
>> 2014-01-30 Scott Merryman <[email protected]>:
>>> It looks like the  -`if'-  is on a different line following the -gen
>>> double...- statement.
>>>
>>> The example below works:
>>>
>>>
>>> sysuse auto,clear
>>> gen lnprice = ln(price)
>>> gen lowweight = (weight < 3000)
>>> gen lowgear = (gear < 3)
>>>
>>> capture program drop nlwage1
>>> program nlwage1
>>>  version 12
>>>  syntax varlist(min=5 max=5) if, at(name)
>>>  local lnwage : word 1 of `varlist'
>>>  local income : word 2 of `varlist'
>>>  local dist1: word 3 of `varlist'
>>>  local dist2: word 4 of `varlist'
>>>  local dist3:word 5 of `varlist'
>>>  tempname k0 k1 k2
>>>  scalar `k0' = `at'[1, 1]
>>>  scalar `k1' = `at'[1, 2]
>>>  scalar `k2' = `at'[1, 3]
>>>  tempvar eterm
>>>  gen double `eterm'=`income'*exp(`k2'*`dist1') ///
>>>      +`income'*exp(`k2'*`dist2') ///
>>>      +`income'*exp(`k2'*`dist3') `if'
>>>  replace `lnwage' = `k0' +`k1'*ln(`eterm') `if'
>>>  end
>>>
>>>  nl wage1 @ lnprice mpg foreign lowweight lowgear, ///
>>>    parameters(k0 k1 k2 ) initial(k0 0.05 k1 0.02 k2 0.03)
>
> *
> *   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