Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Help with maximum likelihood estimation


From   Alexander Shevchenko <[email protected]>
To   [email protected]
Subject   st: Help with maximum likelihood estimation
Date   Tue, 26 Aug 2008 13:54:29 +0400

Hi, statalisters.

I am trying to build a Maximum likelihood model. It is a binary choice model where a choice depends on utilities of alternative. First alternative (sv) is a utility of "offer" and a second one (cv) is a simple average of "offer_hat`j'". There are 680, 364, 165, 56, 10 and 2 variables "offer_hat`j'" in 1st, 2nd and so on periods respectively. Prior to estimation I have generated variable "i" that contains 680, 364, 165, 56, 10 and 2 for the respective time periods.

Now I am sure that the utility function is strictly concave, it is continuous, however when estimating it gives me error "could not calculate numerical derivatives, missing values encountered".

Please find below the script I am using. May be you can tell me what I am doing wrong? May be one more thing to mention is that dataset I have is unbalanced panel.

Thank you very much indeed.

Alex

capture program drop utility
program define utility
	args todo b lnf
	tempvar alpha beta W cv sv lnfj temp sigma
	tempname i

	mleval `alpha'=`b', eq(1) scalar
	mleval `beta'=`b', eq(2) scalar
	mleval `W'=`b', eq(3) scalar


	qui gen double `sv' = (1-exp(-`alpha'*(`W'+offer)^(1-`beta')))/`alpha'

	*qui gen `i'=comb(22-stage_id,3) if stage_id!=20
	*qui replace `i'= 2 if stage_id==20

	qui gen double `cv' = 0
	qui gen double `temp' = 0
	qui gen double `sigma' = 0
		forval j=1/680 {
			qui replace `temp' = (1-exp(-`alpha'*(`W'+offer_hat`j')^(1-`beta')))/`alpha' if time==1
			qui replace `cv' =`cv' + `temp' if time==1
		}

		forval j=1/364 {
			qui replace `temp' = (1-exp(-`alpha'*(`W'+offer_hat`j')^(1-`beta')))/`alpha' if time==2
			qui replace `cv' =`cv' + `temp' if time==2
		}
		forval j=1/165 {
			qui replace `temp' = (1-exp(-`alpha'*(`W'+offer_hat`j')^(1-`beta')))/`alpha' if time==3
			qui replace `cv' =`cv' + `temp' if time==3
		}
		forval j=1/56 {
			qui replace `temp' = (1-exp(-`alpha'*(`W'+offer_hat`j')^(1-`beta')))/`alpha' if time==4
			qui replace `cv' =`cv' + `temp' if time==4
		}

		forval j=1/10 {
			qui replace `temp' = (1-exp(-`alpha'*(`W'+offer_hat`j')^(1-`beta')))/`alpha' if time==5
			qui replace `cv' =`cv' + `temp' if time==5
		}
		forval j=1/2 {
			qui replace `temp' = (1-exp(-`alpha'*(`W'+offer_hat`j')^(1-`beta')))/`alpha' if time==6
			qui replace `cv' =`cv' + `temp' if time==6
		}

	qui replace `cv'=`cv'/i
	qui egen double `sigma'= sd(`cv' - `sv')

	qui gen double `lnfj' = ln(normprob((`cv' - `sv')/sigma)) if $ML_y1==0
	qui replace `lnfj' = ln(normprob((`sv' - `cv')/sigma)) if $ML_y1==1
	mlsum `lnf' = `lnfj'
end

ml model d0 utility (deal=) /beta /W
ml maximize

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index