Here is an article about the FROOT function, which contains a discussion and example: A simple way to find the root of a function of one variable - The DO Loop
For your function, here is an example:
proc iml;
beta = 1; m = 50; k = 1;
seed = 2;
*------------------- Firth -----------------------;
start Firth_score(y) global(X, m);
beta = y[1];
sum_x2 = (X##2)[+];
/* Firth score */
U_star = - (12*m + 5 - 4*sum_x2/(beta**2)) / (4*beta);
return(U_star);
finish;
Call randseed(seed);
U=j(m,1,0); X=j(m,1,0);
Call randgen(U,"uniform");
X = Sqrt( (-2*beta**2)# log(1- U) );
Firth_root = froot("Firth_score", {0.5 1});
print Firth_root;
Firth_root
0.7115471
You can visualize the Firth score to verify the answer:
/* visualize to confirm that the Firth_score is zero at root */
betaVals = T(do(0.5, 1, 0.001));
score = j(nrow(betaVals),1,.);
do j = 1 to nrow(betaVals);
score[j] = Firth_score(betaVals[j]);
end;
title "Firth Score as a Function of Beta";
call series(betaVals, score) grid={x y} other="refline 0/axis=y;";
... View more