Dear all,
I'd like loop both d and theta (i.e., d=0.1(0.05)0.2, and theta=1(0.1)2) for the following program myest. I tried "forvalues after program" and "program within forvalues". Neither works.
Would you please help to figure it out? Thank you.
*****code as below
capture program drop myest
program define myest
version 14
args lnf Xb
tempvar d theta
quietly generate double `d'=0.1
quietly generate double `theta'=1
quietly replace `lnf' = ln(normal((ln(300/((1-exp(-1*`d'-0.1))/(`d'+0.1)*exp(-1*`d'*2)))-`Xb')/`theta')) if $ML_y1==2
quietly replace `lnf' = ln(1-normal((ln(300/((1-exp(-1*`d'-0.1))/(`d'+0.1)*exp(-1*`d'*19)))-`Xb')/`theta')) if $ML_y1==20
quietly replace `lnf' = ln(normal((ln(300/exp(-1*$ML_y1*`d')*((1-exp(-1*`d'-0.1))/(`d'+0.1)))-`Xb')/`theta')-normal((ln(300/exp(-1*($ML_y1-1)*`d')*((1-exp(-1*`d'-0.1))/(`d'+0.1)))-`Xb')/`theta')) if ($ML_y1<20)&($ML_y1>2)
end
qui ml model lf myest (y= x1 x2)
qui ml check
qui ml maximize
display e(ll)
I'd like loop both d and theta (i.e., d=0.1(0.05)0.2, and theta=1(0.1)2) for the following program myest. I tried "forvalues after program" and "program within forvalues". Neither works.
Would you please help to figure it out? Thank you.
*****code as below
capture program drop myest
program define myest
version 14
args lnf Xb
tempvar d theta
quietly generate double `d'=0.1
quietly generate double `theta'=1
quietly replace `lnf' = ln(normal((ln(300/((1-exp(-1*`d'-0.1))/(`d'+0.1)*exp(-1*`d'*2)))-`Xb')/`theta')) if $ML_y1==2
quietly replace `lnf' = ln(1-normal((ln(300/((1-exp(-1*`d'-0.1))/(`d'+0.1)*exp(-1*`d'*19)))-`Xb')/`theta')) if $ML_y1==20
quietly replace `lnf' = ln(normal((ln(300/exp(-1*$ML_y1*`d')*((1-exp(-1*`d'-0.1))/(`d'+0.1)))-`Xb')/`theta')-normal((ln(300/exp(-1*($ML_y1-1)*`d')*((1-exp(-1*`d'-0.1))/(`d'+0.1)))-`Xb')/`theta')) if ($ML_y1<20)&($ML_y1>2)
end
qui ml model lf myest (y= x1 x2)
qui ml check
qui ml maximize
display e(ll)
Comment