我正在尝试ml
在 Stata 中学习编程。作为其中的一部分,我正在运行一个程序myprobit
(代码来自 Gould、Pitblado 和 Sribney 的 Stata 的最大似然估计)。
capture program drop myprobit
program define myprobit
args todo b lnf g negH g1
tempvar xb lj
mleval `xb'=`b'
quietly{
gen double `lj'=normal(`xb') if $ML_y1==1
replace `lj'=normal(-`xb') if $ML_y1==0
mlsum `lnf'=ln(`lj')
if (`todo'==0|`lnf'>= .) exit
replace `g1'= normalden(`xb')/`lj' if $ML_y1==1
replace `g1'=-normalden(`xb')/`lj' if $ML_y1==0
mlvecsum `lnf' `g'=`g1', eq(1)
if (`todo'==1|`lnf'==>.)exit
mlmatsum `lnf' `negH'=`g1'*(`g1'+`xb'),eq(1,1)
}
end
sysuse cancer, clear
gen drug2=drug==2
gen drug3=drug==3
ml model d1 myprobit (died=drug2 drug3 age)
ml check
ml maximize
但是,我得到了一个错误varlist required
:这是它的执行痕迹:
------------------------------------------------------------------------------
-> myprobit 1 __000000 __000001 __000002 __000003
- `begin'
= capture noisily version 11: myprobit 1 __000000 __000001 __000002 __000003
---------------------------------------------------------------------------------------------------------------------------------- begin myprobit ---
- args todo b lnf g negH g1
- tempvar xb lj
- mleval `xb'=`b'
= mleval __000005=__000000
- quietly{
- gen double `lj'=normal(`xb') if $ML_y1==1
= gen double __000006=normal(__000005) if died==1
- replace `lj'=normal(-`xb') if $ML_y1==0
= replace __000006=normal(-__000005) if died==0
- mlsum `lnf'=ln(`lj')
= mlsum __000001=ln(__000006)
- if (`todo'==0|`lnf'>= .) exit
= if (1==0|__000001>= .) exit
- replace `g1'= normalden(`xb')/`lj' if $ML_y1==1
= replace = normalden(__000005)/__000006 if died==1
varlist required
replace `g1'=-normalden(`xb')/`lj' if $ML_y1==0
mlvecsum `lnf' `g'=`g1', eq(1)
if (`todo'==1|`lnf'==>.)exit
mlmatsum `lnf' `negH'=`g1'*(`g1'+`xb'),eq(1,1)
}
------------------------------------------------------------------------------------------------------------------------------------ end myprobit ---
- `end'
= set trace off
------------------------------------------------------------------------------
Fix myprobit.
r(100);
end of do-file
注意:如果似然性评估器更改为 ,程序运行不会出错do
。在这方面的任何建议都将受到高度赞赏。