Dear all,

I am having problems with a function embedded in a customized program. Below is the said function:

real rowvector rs_max2(real matrix X)

{

real scalar j

real rowvector xres

real colvector v

/*designate vector xres to temporarily store the results:*/

xres = J(1, cols(X), .)

/*get the index for the maximum:*/

for(j=1; j<=cols(X); j++){

maxindex(X[.,j], 3, v=., .)

xres[1, j] = X[v[2],j]

}

return(xres)

}

I wrote this function to get the second smallest value for each column of a matrix X. It is part of an .ado program, which is very long. I believe the error occurs within this function because the error message I got when I execute the entire program is:

'real' found where almost anything else expected

(229 lines skipped)

, and the 229 lines from the bottom of the entire program is the line: " real scalar j" or " real rowvector xres"

I have scrutinized this function multiple times, but could not find an error. Could you please help me check which part of it is mistaken? Thank you very much in advance.

I am having problems with a function embedded in a customized program. Below is the said function:

real rowvector rs_max2(real matrix X)

{

real scalar j

real rowvector xres

real colvector v

/*designate vector xres to temporarily store the results:*/

xres = J(1, cols(X), .)

/*get the index for the maximum:*/

for(j=1; j<=cols(X); j++){

maxindex(X[.,j], 3, v=., .)

xres[1, j] = X[v[2],j]

}

return(xres)

}

I wrote this function to get the second smallest value for each column of a matrix X. It is part of an .ado program, which is very long. I believe the error occurs within this function because the error message I got when I execute the entire program is:

'real' found where almost anything else expected

(229 lines skipped)

, and the 229 lines from the bottom of the entire program is the line: " real scalar j" or " real rowvector xres"

I have scrutinized this function multiple times, but could not find an error. Could you please help me check which part of it is mistaken? Thank you very much in advance.

## Comment