[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: RE: st: Programming an iterative regression with converging parameters

From   "Austin Nichols" <[email protected]>
To   [email protected]
Subject   Re: RE: st: Programming an iterative regression with converging parameters
Date   Fri, 15 Aug 2008 06:57:00 -0700

I have not tried to understand your entire enterprise, mostly because
you gave an incomplete reference and an explanation of your goals that
was not immediately clear and an inadequate description of Stata's
response to your code [see], but I
am guessing that your line
  while r_`j'-r_`i'>0.001 {
is simply never true in your data for some reason so the block of code
never executes.  Note that such a condition will never be true if the
second r is bigger than the first in the first observation in the
first iteration, i.e. you are testing whether r_`j' > r_`i' +0.001  in
observation 1.  If you mean to test whether the distance between two
vectors is above some threshold, you want to test whether
abs(total(r_`j')-total(r_`i'))>0.001 in essence, or perhaps
total(abs(r_`j'-r_`i'))>0.001 which requires first calculating the
total or sum over observations.  For example:

g double s=sum(abs(r`j'-r`i'))
while abs(s[_N])>0.001 {
 replace  s=sum(abs(r`j'-r`i'))

Is that what you meant?

To constrain a parameter b to be strictly positive, simply estimate
ln(b) instead, since the most negative ln(b) possible will produce a
nonnegative b when you transform it (though if lnb goes below -709 you
will get b=0 effectively).  But be careful about claiming that
"negative returns and rates of growth do not make sense."  They do
make sense in most fields most of the time, though they may be an
unpleasant case to deal with in a theory.

My guess is that the code you've shown us is an extremely inefficient
way to get where you want to go, but it would be much more productive
if you could post a data example starting with -input- and about 5
obs, then illustrate what the desired endpoint is.  That is much more
likely to fire the imagination of Statalisters.

On Fri, Aug 15, 2008 at 4:02 AM,  <[email protected]> wrote:
> I forgot to ask how to set the constraints that r,g>0 as
> negative returns and rates of growth do not make sense. So
> far I have
> not found a mehtod to set constraints.
I am new to STATA and have to replicate a paper by Easton, Taylor,
Shroff, Soughiannis (2002) about the implicit calculation of the
implied cost of capital r. The problem is that the proxy for the
dependent variable X_cT is caluclated with r, while r itself is to be
estimated from the regression coefficients. They note that an initial
r=0.12 or 12% is used to calculate X_cT. Then it is used as dependent
variable to run the first regression. From the resulting intercept and
regression coefficient the r and growth rate g are calculated. The new
r is used as revised estimate of the implied cost of capital r to
recalculate X_cT. The regression is run again and the process of
estimating r from the coefficients, and recalculating X_cT starts all
over. The logic is simple and straight forward - the programming for a
rookie is not. Reading about STATA Programming I guess that a loop
using the while command is needed, with the iterative regression to
stop when the r from the previous run and the new r are so close as
not changing matterially. I used r_`j'-r_`i'>0.0001 as indicator to
continue with the loop, as the "true" condition. Also r must be
positiv, whereas the forth root can be negative, but is economic
meaningless. How to program constraints I do not know - sounds like
MATA-rogramming then. So I tried it first without the constraints.
Maybe the nl command could work.

Here is my do file, and when executing it I even do not get an error
message, neither results, not anything:

set memory 50m
use "C:\Users\stock.GESS\Desktop\IBES
generate r_1=0.12
generate X_cT_1=x1+x2+x3+x4+[(1+r_1)^3-1]*d0+[(1+r_1)^2-1]*d0+[(1+r_1)-1]*d0
generate depvar=X_cT_1/B0
local i=1
forvalues i=1/100 {
local j=1
while r_`j'-r_`i'>0.001 {
       replace r_`i'=r_`j'
       replace X_cT_`i'=x1+x2+x3+x4+[(1+r_`i')^3-1]*d0+[(1+r_`i')^2-1]*d0+[(1+r_`i')-1]*d0
       replace depvar=X_cT_`i'/B0
       regress depvar indvar
       generate g_`i'=(_b[_cons]+1)^(1/4)-1, replace
       generate r_`j'=(_b[indvar]+(_b[cons]+1))^(1/4)-1, replace
save Data_replication_study_1_X_cT_1.dta
estimates save regression_1, replace
estimates tab

Any suggestions hw to program such a process are highly appreciated.
*   For searches and help try:

© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index