Hello, could someone help me identify what is the problem with this code I tweaked to simulate maximum likelihood in a dynamic multinomial logit model from this article "Estimation of multinomial logit models with unobserved heterogeneity using maximum simulated likelihood": https://journals.sagepub.com/doi/pdf...867X0600600205
I am getting the error that there is an invalid syntax. Thank you!
program define mlogitmodeld0
args todo b lnf
tempvar etha2 etha3 random1 random2 lj pi1 pi2 pi3 sum lnpi L1 L2 last
tempname lnsig1 lnsig2 atrho12 sigma1 sigma2 cov12
mleval `etha2' = `b', eq(1)
mleval `etha3' = `b', eq(2)
mleval `lnsig1' = `b', eq(3) scalar
mleval `lnsig2' = `b', eq(4) scalar
mleval `atrho12' = `b', eq(5) scalar
qui {
scalar `sigma1'=(exp(`lnsig1'))^2
scalar `sigma2'=(exp(`lnsig2'))^2
scalar `cov12'=[exp(2*`atrho12')-1]/[exp(2*`atrho12')+1]* ///
(exp(`lnsig2'))*(exp(`lnsig1'))
gen double `random1' = 0
gen double `random2' = 0
gen double `lnpi'=0
gen double `sum'=0
gen double `L1'=0
gen double `L2'=0
by personid: gen byte `last'=(_n==_N)
gen double `pi1'=0
gen double `pi2'=0
gen double `pi3'=0
}
matrix W = ( `sigma1' , `cov12' \ `cov12' , `sigma2')
capture matrix L=cholesky(W)
if _rc != 0 {
di "Warning: cannot do Cholesky factorization of rho matrix"
}
local l11=L[1,1]
local l21=L[2,1]
local l22=L[2,2]
forvalues r=1/$draws{
qui {
replace `random1' = random_1`r'*`l11'
replace `random2' = random_2`r'*`l22' + random_1`r'*`l21'
replace `pi1'= 1/(1 + exp(`etha2'+`random1')+exp(`etha3'+`random2'))
replace `pi2'= exp(`etha2'+`random1')*`pi1'
replace `pi3'= exp(`etha3'+`random2')*`pi1'
replace `lnpi'=ln(`pi1'*a1+`pi2'*a2+`pi3'*a3)
by personid: replace `sum'=sum(`lnpi')
by personid: replace `L1' =exp(`sum'[_N]) if _n==_N
by personid: replace `L2'=`L2'+`L1' if _n==_N
}
}
qui gen `lj'=cond(!`last',0, ln(`L2'/`$draws'))
qui mlsum `lnf'=`lj'
if (`todo'==0|`lnf'>=.) exit
end
ml model d0 mlogitmodeld0 (newstates = married yearseduc hhsize nchild ndependents h2q8 agesq altisco_1-altisco_9 tenure year_1-year_7 newstates_1t_1 newstates_2t_1 newstates_3t_1 newstates_1t1 newstates_2t1 newstates_3t1) (newstates = married yearseduc hhsize nchild ndependents h2q8 agesq altisco_1-altisco_9 tenure year_1-year_7 newstates_1t_1 newstates_2t_1 newstates_3t_1 newstates_1t1 newstates_2t1 newstates_3t1) /lnsig1 /lnsig2 /atsig12
matrix start = (Init)
ml init start 0.5 0.5 0.5 ,copy
ERROR:
. ml maximize
invalid syntax
r(198);
Related Posts with Dynamic ML model code syntax error for simulation of maximum likelihood
Spectral decomposition in MataHi Mata users, I would like to know if there is a built-in function in Mata that calculates the squ…
Questions about testing equality of survivor functions in matched patient dataI have two different datasets of patients and I would like to perform survival analyses to compare t…
VentilesHello, I want to take a variable of mine, put it into ventiles, then use collapse to graph the mean…
Export trade durationHello, I am trying to assign consecutive years of exports to my data. My data consists of Years, pr…
Power calculation using pairwise matching design.Hi All, For our cluster level specification, we are currently using “clustersampsi” command in Stat…
Subscribe to:
Post Comments (Atom)
0 Response to Dynamic ML model code syntax error for simulation of maximum likelihood
Post a Comment