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 on April 23, and its replacement, is already up and running.

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

st: ML Programming

From   "Jonas Krüger" <>
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 
		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

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

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

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

Thanks in advance
*   For searches and help try:

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