### Error in Loop procedure

Hi there,

I’m still working on the restricted OLS regressions and in the meantime even uploaded an early version of a function package that uses a SQP of GNU R and a bootstrap routine to get coeffs and standard errors.

In order to produce a nice show case of the optimization problem I generate all combination of coefficients with a step size of n. If there are 3 coeffs that are >=0 and should sum up to 1 the matrix can be easily generated via loop. Since gretl has a special "for loop" one could use this loop version in order to fill the percentages in the matrix in one step. However, there is a bug. Have a look. I’m using the current x64 snapshot for windows.

Cheers and a nice first Sunday in Advent

Leon

<hansl>

scalar intN_1_a = 50 # step size of 2 percent

scalar intStep = 1/intN_1_a

eval intStep

matrix mCombis = NA

matrix mCombisALL = NA

set stopwatch

loop for i=0..intN_1_a --quiet

loop for j=0..intN_1_a --quiet

if i+j<=intN_1_a

if i+j == 0

mCombisALL = i ~ j ~ (intN_1_a-i-j)

else

mCombisALL |= i ~ j ~ (intN_1_a-i-j)

endif

endif

endloop

endloop

eval $stopwatch/60

eval rows(mCombisALL)

# correct number of rows since

scalar intSum3 = (intN_1_a)*3 + (1+intN_1_a-3+1)*(1+intN_1_a-3)/2

# for three coeefs I found this closed formula, with more it’s another…

eval intSum3

set stopwatch

loop for (i=0; i<=1; i+=intStep) --quiet

loop for (j=0; j<=1; j+=intStep) --quiet

if i+j<=1

if i+j == 0

mCombis = i ~ j ~ (1-i-j)

else

mCombis |= i ~ j ~ (1-i-j)

endif

endif

endloop

endloop

eval rows(mCombis)

eval $stopwatch

# correct number

scalar intSum3 = (intN_1_a)*3 + (1+intN_1_a-3+1)*(1+intN_1_a-3)/2

eval intSum3

# wrong, WHY? The reason has to do with the.xx999 values and the missing 1s.

<hansl>

<div><div class="WordSection1"> <p class="MsoNormal"><span lang="EN-US">Hi there,<p></p></span></p> <p class="MsoNormal"><span lang="EN-US"> <p></p></span></p> <p class="MsoNormal"><span lang="EN-US">I’m still working on the restricted OLS regressions and in the meantime even uploaded an early version of a function package that uses a SQP of GNU R and a bootstrap routine to get coeffs and standard errors. <p></p></span></p> <p class="MsoNormal"><span lang="EN-US"> <p></p></span></p> <p class="MsoNormal"><span lang="EN-US">In order to produce a nice show case of the optimization problem I generate all combination of coefficients with a step size of n. If there are 3 coeffs that are >=0 and should sum up to 1 the matrix can be easily generated via loop. Since gretl has a special "for loop" one could use this loop version in order to fill the percentages in the matrix in one step. However, there is a bug. Have a look. I’m using the current x64 snapshot for windows.<p></p></span></p> <p class="MsoNormal"><span lang="EN-US"> <p></p></span></p> <p class="MsoNormal"><span lang="EN-US">Cheers and a nice first Sunday in Advent<p></p></span></p> <p class="MsoNormal">Leon</p> <p class="MsoNormal"><p> </p></p> <p class="MsoNormal"><hansl></p> <p class="MsoNormal">scalar intN_1_a = 50 # step size of 2 percent</p> <p class="MsoNormal">scalar intStep = 1/intN_1_a</p> <p class="MsoNormal">eval intStep</p> <p class="MsoNormal">matrix mCombis = NA</p> <p class="MsoNormal">matrix mCombisALL = NA</p> <p class="MsoNormal"><p> </p></p> <p class="MsoNormal">set stopwatch</p> <p class="MsoNormal">loop for i=0..intN_1_a --quiet</p> <p class="MsoNormal"> loop for j=0..intN_1_a --quiet</p> <p class="MsoNormal"> if i+j<=intN_1_a</p> <p class="MsoNormal"> if i+j == 0</p> <p class="MsoNormal"> mCombisALL = i ~ j ~ (intN_1_a-i-j)</p> <p class="MsoNormal"> else </p> <p class="MsoNormal"> mCombisALL |= i ~ j ~ (intN_1_a-i-j)</p> <p class="MsoNormal"> endif </p> <p class="MsoNormal"> endif </p> <p class="MsoNormal"> endloop </p> <p class="MsoNormal">endloop</p> <p class="MsoNormal">eval $stopwatch/60</p> <p class="MsoNormal">eval rows(mCombisALL)</p> <p class="MsoNormal"># correct number of rows since </p> <p class="MsoNormal">scalar intSum3 = (intN_1_a)*3 + (1+intN_1_a-3+1)*(1+intN_1_a-3)/2</p> <p class="MsoNormal"># for three coeefs I found this closed formula, with more it’s another…</p> <p class="MsoNormal">eval intSum3</p> <p class="MsoNormal"><p> </p></p> <p class="MsoNormal"><p> </p></p> <p class="MsoNormal">set stopwatch</p> <p class="MsoNormal">loop for (i=0; i<=1; i+=intStep) --quiet</p> <p class="MsoNormal"> loop for (j=0; j<=1; j+=intStep) --quiet</p> <p class="MsoNormal"> if i+j<=1</p> <p class="MsoNormal"> if i+j == 0</p> <p class="MsoNormal"> mCombis = i ~ j ~ (1-i-j)</p> <p class="MsoNormal"> else </p> <p class="MsoNormal"> mCombis |= i ~ j ~ (1-i-j)</p> <p class="MsoNormal"> endif </p> <p class="MsoNormal"> endif </p> <p class="MsoNormal"> endloop </p> <p class="MsoNormal">endloop</p> <p class="MsoNormal">eval rows(mCombis)</p> <p class="MsoNormal">eval $stopwatch</p> <p class="MsoNormal"># correct number</p> <p class="MsoNormal">scalar intSum3 = (intN_1_a)*3 + (1+intN_1_a-3+1)*(1+intN_1_a-3)/2</p> <p class="MsoNormal">eval intSum3</p> <p class="MsoNormal"># wrong, WHY? The reason has to do with the.xx999 values and the missing 1s.</p> <p class="MsoNormal"><p> </p></p> <p class="MsoNormal"><hansl><p></p></p> <p class="MsoNormal"><p> </p></p> <p class="MsoNormal"><p> </p></p> </div></div>