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


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

st: Mata calls on Stata variables and macros


From   Brad Jeffrey Hershbein <bjhersh@umich.edu>
To   statalist@hsphsun2.harvard.edu
Subject   st: Mata calls on Stata variables and macros
Date   Sat, 17 Apr 2010 19:00:30 -0400

Dear Statalisters,

I would like to solve a (cubic) polynomial equation where one of the coefficients of the polynomial is a variable in my dataset and the other coefficients are stored as scalars. That is, I want to solve for the roots of Ax^3 + Bx^2 + Cx + D = 0, where D is the variable Z in my dataset, and A, B, and C are stored in the scalars a1, b1, and c1, respectively. The values of A, B, C, and D are such that there is only one positive, real root in all cases, and I would like that root to be a new variable in the dataset.

I know the Mata routine polyroots can find the roots of a polynomial, but I cannot figure out how to simultaneously pass the scalars and Z for polyroots to take as arguments, and how to return the positive real root as a new variable to Stata.

Thank you for your consideration.

Brad Hershbein
University of Michigan
*
*   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