Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • RE-POST: Error message when applying cholesky decomposition for random draws: ""too few variables specified""

    Hello,
    Following Professor Jenkins advice, I re-post with a better editing and using code delimiters. Sorry for not doing so before.
    I am trying to estimate parameters of a utility function throu Simulated Maximum Likelihood. My code is based in the code of the article called "Estimation of multinomial logit models with unobserved heterogeneity using maximum simulated likelihood" by professors Peter Haan and Arne Uhlendorff, at The Stata Journal (2006), 6, Number 2, pp. 229–245.
    My adapted code is the following:

    Code:
    program drop _all
    * damos nombre al programa y determinamos la version del stata sobre la que se hace el programa
    sort strata H_obs
    program define clogit_micropar_d0
        version 11.2
        args todo b lnf
        tempvar etha1 etha2 etha3 beta1 beta2 fc L1 L2 numer sumnumer denom
        tempname lnsig1 lnsig2 lnsig3 atrho12 atrho13 atrho23 sigma1 sigma2 sigma3 cov12 cov13 cov23 l11 l21 l31 /*
    */    l22 l32 l33
    local didep "$ML_y1"
    mleval `etha1' = `b', eq(1)
    mleval `etha2' = `b', eq(2)
    mleval `etha3' = `b', eq(3)
    mleval `beta1' = `b', eq(4)
    mleval `beta2' = `b', eq(5)
    mleval `fc'    = `b', eq(6)
    mleval `lnsig1' = `b', eq(7) scalar
    mleval `lnsig2' = `b', eq(8) scalar
    mleval `lnsig3' = `b', eq(9) scalar
    mleval `atrho12' = `b', eq(10) scalar
    mleval `atrho13' = `b', eq(11) scalar
    mleval `atrho23' = `b', eq(12) scalar
    qui gen double `L1'=0
    qui gen double `L2'=0
    qui gen double `numer'=0
    qui gen double `sumnumer'=0
    qui gen double `denom'=0
    scalar `sigma1'=(exp(`lnsig1'))^2
    scalar `sigma2'=(exp(`lnsig2'))^2
    scalar `sigma3'=(exp(`lnsig3'))^2
    scalar `cov12'=[exp(2*`atrho12')-1]/[exp(2*`atrho12')+1]*(exp(`lnsig2'))*(exp(`lnsig1'))
    scalar `cov13'=[exp(2*`atrho13')-1]/[exp(2*`atrho13')+1]*(exp(`lnsig3'))*(exp(`lnsig1'))
    scalar `cov23'=[exp(2*`atrho23')-1]/[exp(2*`atrho23')+1]*(exp(`lnsig3'))*(exp(`lnsig2'))
    matrix W = (`sigma1' , `cov12' , `cov13' \ `cov12' , `sigma2' , `cov23' \ `cov13' , `cov23' , `sigma3')
    capture matrix U = cholesky(W)
    if _rc != 0 {
    di "Warning: cannot do Cholesky factorization of rho matrix"
    }
    local l11=U[1,1]
    local l21=U[2,1]
    local l31=U[3,1]
    local l22=U[2,2]
    local l32=U[3,2]
    local l33=U[3,3]
    forvalues r = 1/100{
    qui {
    gen double `random1' = randomc1_`r'*`l11'  
    gen double `random2' = randomc2_`r'*`l22' + randomc1_`r'*`l21'
    gen double `random3' = randomc3_`r'*`l33' + randomc2_`r'*`l32' + randomc1_`r'*`l31'
    gen double `y'=y`r'-((`fc'+`random3')*d_fc)
    gen double `ysq'=`y'^2
    gen double `yh'=`y'*h
    gen double `utility'=`etha1'*`ysq'+`etha2'*hsq+`etha3'*`yh'+(`beta1'+`random1')*`y'+(`beta2'+`random2')*h
    replace `numer'=exp(`utility')
    by strata: replace `sumnumer'=sum(`numer')
    by strata: replace `denom'=`sumnumer'[_N]
    replace `L1'=(`numer'/`denom')*`didep'
    replace `L2'=`L1'+`L2'
    drop `y' `yh' `ysq' `numer' `sumnumer' `denom' `L1' `utility' `random1' `random2' `random3'
    }
    }
    mlsum `lnf'=ln(`L2'/100)
    if (`todo'==0 | `lnf'>=.) exit
    end
    
    ml model d0 clogit_micropar_d0 (ysq:) (hsq:) (yh:) (y: edad1 edad2 i.educacion1_mi d_guarani d_viveconpadre) /*
    */ (h: edad1 edad2 i.educacion1_mi d_guarani d_viveconpadre PIB_3rTrimPtos d_aged60more) (fc: d_AsunCentral) /*
    */ /lnsig1 /lnsig2 /lnsig3 /atrho12 /atrho13 /atrho23
    
    ml check

    My problem is that when cheking with "ml check" Stata is showing an error message ""too few variables specified"... (image below) after
    gen double `random1' = randomc1_`r'*`l11'


    Click image for larger version

Name:	error image.jpg
Views:	1
Size:	376.3 KB
ID:	978921



    I don't know the exact reason of this message. If any colleague could help me I would thank him a lot. Thank you professor Jenkins again for your advice.
    Best wishes,
    Ernesto

  • #2
    Extract from your program:
    Code:
    gen double `random1' = randomc1_`r'*`l11' 
    gen double `random2' = randomc2_`r'*`l22' + randomc1_`r'*`l21'
    gen double `random3' = randomc3_`r'*`l33' + randomc2_`r'*`l32' + randomc1_`r'*`l31'
    gen double `y'=y`r'-((`fc'+`random3')*d_fc)
    gen double `ysq'=`y'^2
    gen double `yh'=`y'*h
    gen double `utility'=`etha1'*`ysq'+`etha2'*hsq+`etha3'*`yh'+(`beta1'+`random1')*`y'+(`beta2'+`random2')*h
    None of these variables that you wish to generate are listed in your tempvar statement. My guess is that they should be.
    NB (a) please do not use screenshots to show us output; use CODE delimiters, as the FAQ instructs. (b) Also as the FAQ states, you should have also told us that you're not using Stata 13 (version 11.2 it appears) -- diagnoses and recommendations can vary depending on the version you have. (c) have you made the name re-registration change yet, as requested in the earlier thread
    ?

    Comment


    • #3
      Thank you Prof. Jenkins. Yes, I have already re-registered with my full name. Thank you.

      Comment

      Working...
      X