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, is already up and running.

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

st: passing extra information to function evaluator program nl

From   Ben Zipperer <>
Subject   st: passing extra information to function evaluator program nl
Date   Tue, 23 Mar 2010 12:14:26 -0400

I am interested in using Stata to find a real roots to a single
polynomial several times, where the coefficients vary each time.  I
basically want to apply Newton's method or something else to vectors
of coefficients. I originally planned to restrict the solver at to a single polynomial
and then iterate it, changing the coefficients at each iteration.
However, I can't figure out how to pass the coefficients to the
function evaluator program. How do I do this? Do I modify the syntax
statement of the program? Or should I try a different strategy?

For example, let's say the rows of the following matrix form the
coefficients for a quadratic polynomial

mat def M = (1,2,3\ 4,5,6\ 7,8,9)

Then the nl program evaluator program is something like

capture program drop nlpolysolve
program nlpolysolve

        syntax varlist(min=1 max=1) [if], at(name)

        tempname x z
        scalar `x' = `at'[1, 1]
        scalar `z' = `at'[1, 2]

        tempvar yh
	// the real polynomial
        gen double `yh' = a_`i' * x^2 + b_`i' * `x' + c_`i' + 1 in 1

        replace `yh' = 1 - `z' in 2
        replace `varlist' = `yh'


And my iterations are something like

forvalues i=1/3 {
 set obs 2
 gen y = 0
 replace y = 1 in 1

 local a_`i' = M[`i',1]
 local b_`i' = M[`i',2]
 local c_`i' = M[`i',3]

 nl polysolve @ y, parameters(A B) initial(A 0.5 B 1)
stuffiwanttopass(a_`i' b_`i' c_i')


How do I pass the entries of the matrix to the nlpolysolve program above?

*   For searches and help try:

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