Dear all,
I am working on a problem that requires the calculation of four parameters
using a simple iterative algorithm. These four parameters will be used for
additional calculations. Part of the the do-file is shown below.
The problem is the fact I have a number X of observations (X always >= 2).
Despite to the fact that my implementation works really well for _N==1, I
could not think about a loop to restore the scalar z to 1 (scalar z = 1)
when the first run ends. As a result, this implementation only achieves
correct convergence for the first observation, since the scalar z,in the
second run (2nd observation), is already smaller than the epsilon value
previously specified.
How could I solve this problem?
part of a do-file that works well for _N==1:
.
.
.
scalar w = pAB_null
scalar x = ((pAB_null*pab_null)/((pAB_null*pab_null)+(pAb_null*paB_null)))
gene pAB =.
gene pAb=.
gene paB=.
gene pab=.
set more off
scalar z = 1
while z > 0.000000000001 {
scalar pABold = w
replace pAB = ((A*2)+B+D+(E*x))/((a+b+c)*(2))
replace pAb = ((B)+(C*2)+((E)*(1-x))+(F))/((a+b+c)*(2))
replace pab = (((E)*(x))+(F)+(H)+(I*2))/((a+b+c)*(2))
replace paB = 1-pAB-pAb-pab
scalar x = ((pAB*pab)/((pAB*pab)+(pAb*paB)))
scalar w = pAB
scalar z = abs(pABold-pAB)
}
.
.
.
Again, I will be grateful for your help.
Sincerely yours,
Tiago
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/