Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: ML Programming


From   "Jonas Krüger" <jonas.krueger-h71@rub.de>
To   statalist@hsphsun2.harvard.edu
Subject   st: ML Programming
Date   6 Jun 2013 15:10:11 +0200

Hi everyone.
I have some issues with my ML program. I try to estimate a structural 
labor supply model.

Here is the Code first:
----------------------------------------------------------------------------------------------
sort cupid Hc
program ML
	args todo b lnf tempvar beta1 beta2 beta3 L1 alpha1 alpha2 alpha3 
alpha4 alpha5  numer sum denom
	tempname sigma1 lnsig1 l11 sigma2 lnsig2 l22 sigma3 lnsig3 l33
	mleval `beta1'=`b', eq(1)
	mleval `beta2'=`b', eq(2)
	mleval `beta3'=`b', eq(3)
	mleval `lnsig1'=`b',  scalar eq(4)
        mleval `lnsig2'=`b',  scalar eq(5)
	mleval `lnsig3'=`b',  scalar eq(6)
	qui gen double `L1'=0, scalar
	qui gen double `numer'=0
	qui gen double `sum'=0
	qui gen double `denom'=0
	scalar `sigma1'=(exp(`lnsig1'))^2
	scalar `sigma2'=(exp(`lnsig2'))^2
	scalar `sigma3'=(exp(`lnsig3'))^2
	matrix f=(`sigma1' , 0 , 0 \ 0 , `sigma2' , 0 \ 0 , 0 , `sigma3')
	capture matrix U=cholesky(f)
	scalar `l11'=U[1,1]
	scalar `l22'=U[2,2]
	scalar `l33'=U[3,3]
	forvalues r=1/50{
		qui gen double `random1'=random1_`r'*`l11'
		qui gen double `random2'=random2_`r'*`l22'
		qui gen double `random3'=random3_`r'*`l33'
		qui gen double `yhf'=y*fh
		qui gen double `yhm'=y*hm
		qui gen double `ysq'=y^2
		*------------------------------------------------------------------------------------------------*
		qui gen double 
`utility'=`alpha1'*`ysq'+`alpha2'*hfsq+`alpha3'*hmsq+`alpha4'*hfhm+`alpha5'*`yhf'
		+`alpha6'`yhm'+(`beta1'+`random1')*`y'+(`beta2'+`random2')*fh+(`beta3'+`random3')*hm
		qui gen double ‘numer’=exp(`utility')
		qui by cupid: gen double `sum'=sum(`numer') if didep==1
		qui by cupid: gen double `denom'=sum[_N]
		qui gen double `L1'=(`numer'/`denom')
		*-----------------------------------------------------------------------------------------------------*

	} //forvalues r=1/50

	mlsum `lnf'=ln(`L1'/50) if (`todo'==0 | `lnf'>=.) exit

end
ml model d0 ML (`utility' = `beta1' `beta2' `beta3' `alpha1' `alpha2' 
`alpha3' `alpha4' `alpha5'), maximize
-----------------------------------------------------------------------------------------------------


The Problems are:
1. Stata gives the error: = invalid name
r(198);
ml check stops at:  mleval `beta2'=`b', eq(2)



2. How can I control which variables are used for: (beta1*x+random) 
etc.
I want that stata is only using some variables there. E.g. Schooling, 
age etc.

Thanks in advance
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index