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: RE: Iterative solving of an equation


From   Austin Nichols <[email protected]>
To   [email protected]
Subject   Re: st: RE: Iterative solving of an equation
Date   Tue, 20 Apr 2010 17:02:15 -0400

David --
You could just do some algebra and write out the formula for the solutions
(I'm guessing you have two complex roots and one positive real root for
all these problems), or loop over obs in Mata:

ssc inst moremata
clear all
set obs 10
g Price_0 = 100
g BookValue_0 = 50
g EPS_1 = 3
g BookValue_1 = 52
g EPS_2 = 4.5
g g = _n/100
g x=.
mata
v=J(1,1,.)
st_view(v,.,"x Price_0 BookValue_0 EPS_1 BookValue_1 EPS_2 g")
function y(x,a,b,c,d,e,f) {
return(-50*(1+x)^2*(x-f)+(3-50*x)*(1+x)*(x-f)+
(4-52*x)*(x-.04)+(4.5-54*x)*(1+f))
}
for (i=1;i<=rows(v);i++) {
r=mm_root(x=.,&y(),0,1,1e-9,1000,v[i,2],
v[i,3],v[i,4],v[i,5],v[i,6],v[i,7])
v[i,1]=x
}
end
l, noo


On Tue, Apr 20, 2010 at 8:56 AM, Feiveson, Alan H. (JSC-SK311)
<[email protected]> wrote:
> David - One way is to use -nl-
>
> See http://www.stata.com/support/faqs/lang/nl.html
>
> Al Feiveson
>
> -----Original Message-----
> From: [email protected] [mailto:[email protected]] On Behalf Of David Scheuer
> Sent: Tuesday, April 20, 2010 4:18 AM
> To: [email protected]
> Subject: st: Iterative solving of an equation
>
> I am rebuilding cost of capital models, which determine cost of capital implied as the internal rate of return from a valuation model.
>
> For instance, let me assume this is the first line in my dataset and I want to solve the following equation.
>
> Price_0 = 100
> BookValue_0 = 50
> EPS_1 = 3
> BookValue_1 = 52
> EPS_2 = 4.5
> g = 0.04
> x =?
>
> 100=50+(3-x*50)/(1+x)+(4-x*52)/((1+x)^2)+((4.5-x*54)*1.04)/((x-0.04)*(1+x)^2)
>
> For example, in Excel, I would let the "Solver" find the solution for x.
> How can I program STATA to find solutions like this for me?
*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index