Hello everyone,
I trying find the value, x, the equates the average of variable2 to variable1. Below is my attempt using Mata but I keep on getting errors. Please can someone help correct the errors in the code below.
Thank you.
Patrick
Errors:
variable1 = min(1, max(0, (0.95 :- SWCIndex) :* conv_factor))
' ' found where almost anything else expected
r(3000);
: variable2 = min(1, max(0, 1 :- x :- YieldIndex))
' variable2' found where almost anything else expected
r(3000);
I trying find the value, x, the equates the average of variable2 to variable1. Below is my attempt using Mata but I keep on getting errors. Please can someone help correct the errors in the code below.
Thank you.
Patrick
Errors:
variable1 = min(1, max(0, (0.95 :- SWCIndex) :* conv_factor))
' ' found where almost anything else expected
r(3000);
: variable2 = min(1, max(0, 1 :- x :- YieldIndex))
' variable2' found where almost anything else expected
r(3000);
Code:
mata void myfunc(todo, x, lnf, g, H) { SWCIndex=st_data(., "SWCIndex") conv_factor=st_data(.,"conv_factor") YieldIndex=st_data(.,"YieldIndex") variable1 = min(1, max(0, (0.95 :- SWCIndex) :* conv_factor)) variable2 = min(1, max(0, 1 :- x :- YieldIndex)) mean_v1=mean(variable1) mean_v2=mean(variable2) diff_sq=(mean_v1-mean_v2)^2 lnf=-diff_sq } S = optimize_init() optimize_init_which(S, "max") optimize_init_evaluator(S, &myfunc()) optimize_init_params(S, 0) bh = optimize(S) bh end clear input double YieldIndex float SWCIndex double conv_factor 1.0861081686220508 .8990123 .6226526011135668 .6649476376589332 .8974741 .6226526011135668 .5527689833452102 .9240186 .6226526011135668 .9253806198611291 .9500761 .6226526011135668 .9087439508922139 1.1295747 .6226526011135668 1.2941161617887758 1.0016987 .6226526011135668 .3341956330126147 .6080579 .6226526011135668 .853106566143711 1.3886855 .6226526011135668 1.4052729869411842 1.1745064 .6226526011135668 1.135791047177306 1.0770227 .6226526011135668 .9909411357309351 .8795984 .6226526011135668 .7024821439818003 .9564832 .6226526011135668 .7824689060953668 1.0973326 .6226526011135668 1.316751439047902 1.1611431 .6226526011135668 1.6404846532462987 1.2310717 .6226526011135668 .909491036549925 .9555679 .6226526011135668 1.2837267687754703 1.0622913 .6226526011135668 1.2891894358766425 1.0278761 .6226526011135668 1.3410032409929848 1.3822783 .6226526011135668 .4042373654867438 1.0403242 .6226526011135668 end
Comment