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 at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: non linear equation difficulties with nl function evaluation program


From   Carolina Lopez <carolina.univ@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   st: non linear equation difficulties with nl function evaluation program
Date   Tue, 24 Aug 2010 22:52:50 +0200

Greetings everyone,

I am working on the estimation of this transport cost function, and
getting issues with the func prog using nl:
lcostratio= { [a(1+a+(n-2))] / [(1+a-k)(1+a+k(n-1)] } {
b1lpko+b2lsalratio} - { [ak] / [ 1+a-k)(1+a+k(n-1)] } { b3sum_lpko +
b4sum_lsalratio  } +
{ [1+(n-1)k ] / [ [ 1+a+k(n-1)]} lna

My dataset is a pooled cross section.

Variables: lcostratio, lpko, lsalratio, sum_lpko, sum_salratio, n
Parameters I want to estimate: a (alpha), k, b0, b1, b2, b3, b4, b5

I wrote this function evaluator program:

program define nltest
version 11
syntax varlist(min=6 max=6) if, at(name)
local lcostratio: word 1 of `varlist'
local lpko: word 2 of `varlist'
local lsalratio: word 3 of `varlist'
local sum_lpko: word 4 of `varlist'
local sum_lsalratio: word 5 of `varlist'
local n: word 6 of `varlist'
tempname b0 alpha k b1 b2 b3 b4 b5
scalar `b0' = `at'[1,1]
scalar `alpha' = `at'[1,2]
scalar `k' = `at'[1,3]
scalar `b1' = `at'[1,4]
scalar `b2' = `at'[1,5]
scalar `b3' = `at'[1,6]
scalar `b4' = `at'[1,7]
scalar `b5' = `at'[1,8]
tempvar term1 term2 term3 term4 term5 term6 term7
generate double `term1' = (`alpha'*(1+`alpha'+(`n'-2)*`k')) `if'
generate double `term2' = ((1+`alpha'-`k')*(1+`alpha'+(`n'-1)*`k')) `if'
generate double `term3' = (`alpha'*`k') `if'
generate double `term4' = ((1+`alpha'-`k')*(1+`alpha'+(`n'-1)*`k')) `if'
generate double `term5' = (1+(`n'-1)*`k') `if'
generate double `term6' = (1+`alpha'+`k'*(`n'-1)) `if'
generate double `term7' = log(`alpha') `if'
replace `lcostratio' = (`b0' +
(`term1'/`term2')*(`b1'*`lpko'+`b2'*`lsalratio') +
(`term3'/`term4')*(`b3'*`sum_lpko'+`b4'*`sum_lsalratio') -
(`term5'/`term6')*(`b5'*`term7')) `if'
end

matrix startv = (0, 0.1, 0.2, 0, 0, -2, -2, 0)

Different estimations I tried:

1) nl test @ lcostratio lpko lsalratio sum_lpko sum_lsalratio n if
incent==1, parameters(b0 alpha k b1 b2 b3 b4 b5) initial(startv)
I get error: convergence not achieved r(430)
I am not sure I am introducing n correctly here, since I do not expect
a parameter, I just want it to feed data for my terms.

2) nl test @ lcostratio lpko lsalratio sum_lpko sum_lsalratio n,
parameters(b0 alpha k b1 b2 b3 b4 b5) initial(startv)
Removing the sample restriction I do get convergence (though not
significance in results)
Is this the right way to estimate the equation? Do I have to introduce
n as a regressor for it to be used in the "terms"?

3) nl test @ lcostratio lpko lsalratio sum_lpko sum_lsalratio,
parameters(b0 alpha k b1 b2 b3 b4 b5) initial(startv)
I get this error: nltest returned 102 verify that nltest is a function
evaluator program r(102);

4) nl test @ lcostratio lpko lsalratio sum_lpko sum_lsalratio if
incent==1, parameters(b0 alpha k b1 b2 b3 b4 b5) initial(startv)
Removing n from the func program (delete line: local n: word 6 of `varlist')
I do get convergence and not completely signifcant results.

Please could you advice on the adequate way of estimating this equation?

Many thanks,
Carolina

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