Hi everyone,
I'm trying to write a maximum likelihood function for a given model.
The specification is the following:
- If y<0: LN[1/SQRT(2*PI()*Sigma_hat^2)]-[(1/(2*Sigma_hat^2)]*(Y+Alpha_1-Beta_hat*X)^2
- If y>0: LN[1/SQRT(2*PI()*Sigma_hat^2)]-[1/(2*Sigma_hat^2)]*(Y+Alpha_2-Beta_hat*X)^2
- If y=0: LN[NORMSDIST((Alpha_2-Beta_hat*X)/Sigma_hat)-NORMSDIST((Alpha_1-Beta_hat*X)/Sigma_hat)]
Alpha_1 must be <=0, Alpha_2 must be >=0, and Beta_hat>=0. The
objective is to obtain, mainly, Alpha_1 and Alpha_2.
I was able to program this in Excel (using solver), but I can't do
this in Stata. The program I've written in Stata is the following
(which, for obvious reasons, isn't working):
program mymlprog
version 10.0
args y x
quietly replace `y' = ln(1/sqrt(2*_pi*Sigma_hat^2))-
((1/(2*Sigma_hat^2))*(`y'+Alpha_1-Beta_hat*`x')^2 if $ML_y1 <0
quietly replace `y' =
ln(normal((Alpha_2-Beta_hat*`x')/Sigma_hat)-normal((Alpha_1-Beta_hat*`x')/Sigma_hat))
if $ML_y1 == 0
quietly replace `y' =
ln[1/sqrt(2*_pi*Sigma_hat^2)]-(1/(2*Sigma_hat^2))*(`y'+Alpha_2-Beta_hat*`x')^2
if $ML_y1 > 0
end
My problems are:
- How can I use Sigma_hat as a component of my model;
- How do I get Alpha_1 and Alpha_2.
If anyone has an idea at least of how to start, I would be really grateful!
Best,
B.
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/