Announcement

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

  • MLE choice under risk

    Dear collegues,

    I am programming my MLE model, however it is impossible to find feasible value. The model specification is very simple, as i'm trying to estimate a parametric model to get the alpha (CRRA) of the utiliy function (expo, or prelec).

    Here is my code

    program define ML_eut0

    args lnf r
    tempvar prob1l prob2l prob3l prob4l prob5l prob1r prob2r prob3r prob4r prob5r y1 y2 y3 y4 y5 x1 x2 x3 x4 x5 euL euR euDiff euRatio tmp lnf_eut lnf_pt p1 p2 p3 p4 p5 f1 f2


    quietly {

    * construct likelihood for EUT
    generate double `prob1l' = $ML_y2
    generate double `prob2l' = $ML_y3
    generate double `prob3l' = $ML_y4
    generate double `prob4l' = $ML_y5
    generate double `prob5l' = $ML_y6

    generate double `prob1r' = $ML_y7
    generate double `prob2r' = $ML_y8
    generate double `prob3r' = $ML_y9
    generate double `prob4r' = $ML_y10
    generate double `prob5r' = $ML_y11

    generate double `y1' = $ML_y12
    generate double `y2' = $ML_y13
    generate double `y3' = $ML_y14
    generate double `y4' = $ML_y15
    generate double `y5' = $ML_y16

    generate double `euL' = ((`prob1l'*`y1')^`r')+((`prob2l'*`y2')^`r')+((`pro b3l'*`y3')^`r')+((`prob4l'*`y4')^`r')+((`prob5l'*` y5')^`r')


    generate double `x1' = $ML_y17
    generate double `x2' = $ML_y18
    generate double `x3' = $ML_y19
    generate double `x4' = $ML_y20
    generate double `x5' = $ML_y21

    generate double `euR' = ((`prob1r'*`x1')^`r')+((`prob2r'*`x2')^`r')+((`pro b3r'*`x3')^`r')+((`prob4r'*`x4')^`r')+((`prob5r'*` x5')^`r')

    generate double `euDiff' = `euL' - `euR'

    replace `lnf' = ln($cdf( `euDiff')) if $ML_y1==1
    replace `lnf' = ln($cdf(-`euDiff')) if $ML_y1==0


    }
    end

    ml model lf ML_eut0 (r: choice prob_a_1 prob_a_2 prob_a_3 prob_a_4 prob_a_5 prob_b_1 prob_b_2 prob_b_3 prob_b_4 prob_b_5 prize_a_1 prize_a_2 prize_a_3 prize_a_4 prize_a_5 prize_b_1 prize_b_2 prize_b_3 prize_b_4 prize_b_5 = )

    Thanks for the support.


    Ruggiero

  • #2
    I can immediately notice four issues. First, you have incorrectly specified your EUT preference functional. Note that you're applying your power transformation to the product of a probability and an outcome: you should leave the probability alone. Second, Stata uses r = 0 as initial value, which is at the boundary of the parametric space that satisfies the income monotonicity of the utility function. I suggest that you go for either an alternative functional form of the CRRA utility function, u(M) = M^(1-rra)/(1-rra), and estimate the rra coefficient directly; or re-parameterise your power function as u(M) = M^exp(rho) and esimtate rho = ln(r) in lieu of r. Third, you are incorrectly assuming that the scale of the latent error term is equal to unity. You can identify the scale of the error term and should estimate it as a free parameter. This model is different from the textbook probit/logit model which requires scale normalisation. Fourth, I don't quite see where and how the global -cdf- has been defined.

    Comment


    • #3
      Hello there Hong Il Yoo, It is nice that you are on this topic. I on the other hand am trying to use a similar approach using code from a paper that simultaneously estimated risk and time preference parameters. My problem is that I need to edit out the code that estimates the time preference parameters. The ML piece of code looks like the following;


      Code:
      program define ML_pt
      
      args lnf alpha sigma lambda delta beta
      tempvar prob1 prob2 prob3 prob4 yA1 yA2 yB1 yB2 tau task0 task1 task2 task3 task4 task5 \\
      task6 task7 task8 task9 task10 task11 task12 task13 task14 task15 task16
      tempvar euA euB euDiff euRatio tmp lnf_eut lnf_pt p1 p2 f1 f2
      
      syntax varlist [if] [in] [fweight pweight] [, noLOg Robust CLuster(varname) svy EForm *]
      marksample touse
      if "`svy'" != "" {
      svymarkout `touse'
      }
      
      quietly {
      
      generate double `tau' = $ML_y10
      
      generate double `task0' = $ML_y11
      generate double `task1' = $ML_y12
      generate double `task2' = $ML_y13
      generate double `task3' = $ML_y14
      generate double `task4' = $ML_y15
      generate double `task5' = $ML_y16
      generate double `task6' = $ML_y17
      generate double `task7' = $ML_y18
      generate double `task8' = $ML_y19
      generate double `task9' = $ML_y20
      generate double `task10' = $ML_y21
      generate double `task11' = $ML_y22
      generate double `task12' = $ML_y23
      generate double `task13' = $ML_y24
      generate double `task14' = $ML_y25
      generate double `task15' = $ML_y26
      generate double `task16' = $ML_y27
      
      generate double `prob1' = 1/exp(ln(1/$ML_y2))^`alpha' if `task0'==1
      generate double `prob2' = 1/exp(ln(1/$ML_y3))^`alpha' if `task0'==1
      generate double `prob3' = 1/exp(ln(1/$ML_y4))^`alpha' if `task0'==1
      generate double `prob4' = 1/exp(ln(1/$ML_y5))^`alpha' if `task0'==1
      
      generate double `yA1' = .
      replace `yA1' = ( $ML_y6)^(`sigma') if $ML_y6>=0
      replace `yA1' = (-`lambda')*(-$ML_y6)^(`sigma') if $ML_y6<0
      
      generate double `yA2' = .
      replace `yA2' = ( $ML_y7)^(`sigma') if $ML_y7>=0
      replace `yA2' = (-`lambda')*(-$ML_y7)^(`sigma') if $ML_y7<0
      
      generate double `yB1' = .
      replace `yB1' = ( $ML_y8)^(`sigma') if $ML_y8>=0 & `task0'==1
      replace `yB1' = ((`beta')*(exp((-`delta')*(`tau'))))*(( $ML_y8)^(`sigma')) if $ML_y8>=0 & `task1'==1
      replace `yB1' = ((`beta')*(exp((-`delta')*(`tau'))))*(( $ML_y8)^(`sigma')) if $ML_y8>=0 & `task2'==1
      replace `yB1' = ((`beta')*(exp((-`delta')*(`tau'))))*(( $ML_y8)^(`sigma')) if $ML_y8>=0 & `task3'==1
      replace `yB1' = ((`beta')*(exp((-`delta')*(`tau'))))*(( $ML_y8)^(`sigma')) if $ML_y8>=0 & `task4'==1
      replace `yB1' = ((`beta')*(exp((-`delta')*(`tau'))))*(( $ML_y8)^(`sigma')) if $ML_y8>=0 & `task5'==1
      replace `yB1' = ((`beta')*(exp((-`delta')*(`tau'))))*(( $ML_y8)^(`sigma')) if $ML_y8>=0 & `task6'==1
      replace `yB1' = ((`beta')*(exp((-`delta')*(`tau'))))*(( $ML_y8)^(`sigma')) if $ML_y8>=0 & `task7'==1
      replace `yB1' = ((`beta')*(exp((-`delta')*(`tau'))))*(( $ML_y8)^(`sigma')) if $ML_y8>=0 & `task8'==1
      replace `yB1' = ((`beta')*(exp((-`delta')*(`tau'))))*(( $ML_y8)^(`sigma')) if $ML_y8>=0 & `task9'==1
      replace `yB1' = ((`beta')*(exp((-`delta')*(`tau'))))*(( $ML_y8)^(`sigma')) if $ML_y8>=0 & `task10'==1
      replace `yB1' = ((`beta')*(exp((-`delta')*(`tau'))))*(( $ML_y8)^(`sigma')) if $ML_y8>=0 & `task11'==1
      replace `yB1' = ((`beta')*(exp((-`delta')*(`tau'))))*(( $ML_y8)^(`sigma')) if $ML_y8>=0 & `task12'==1
      replace `yB1' = ((`beta')*(exp((-`delta')*(`tau'))))*(( $ML_y8)^(`sigma')) if $ML_y8>=0 & `task13'==1
      replace `yB1' = ((`beta')*(exp((-`delta')*(`tau'))))*(( $ML_y8)^(`sigma')) if $ML_y8>=0 & `task14'==1
      replace `yB1' = ((`beta')*(exp((-`delta')*(`tau'))))*(( $ML_y8)^(`sigma')) if $ML_y8>=0 & `task15'==1
      
      replace `yB1' = (-`lambda')*(-$ML_y8)^(`sigma') if $ML_y8<0 & `task0'==1
      replace `yB1' = ((`beta')*(exp((-`delta')*(`tau'))))*((-`lambda')*(-$ML_y8)^(`sigma')) if $ML_y8<0 & `task1'==1
      replace `yB1' = ((`beta')*(exp((-`delta')*(`tau'))))*((-`lambda')*(-$ML_y8)^(`sigma')) if $ML_y8<0 & `task2'==1
      replace `yB1' = ((`beta')*(exp((-`delta')*(`tau'))))*((-`lambda')*(-$ML_y8)^(`sigma')) if $ML_y8<0 & `task3'==1
      replace `yB1' = ((`beta')*(exp((-`delta')*(`tau'))))*((-`lambda')*(-$ML_y8)^(`sigma')) if $ML_y8<0 & `task4'==1
      replace `yB1' = ((`beta')*(exp((-`delta')*(`tau'))))*((-`lambda')*(-$ML_y8)^(`sigma')) if $ML_y8<0 & `task5'==1
      replace `yB1' = ((`beta')*(exp((-`delta')*(`tau'))))*((-`lambda')*(-$ML_y8)^(`sigma')) if $ML_y8<0 & `task6'==1
      replace `yB1' = ((`beta')*(exp((-`delta')*(`tau'))))*((-`lambda')*(-$ML_y8)^(`sigma')) if $ML_y8<0 & `task7'==1
      replace `yB1' = ((`beta')*(exp((-`delta')*(`tau'))))*((-`lambda')*(-$ML_y8)^(`sigma')) if $ML_y8<0 & `task8'==1
      replace `yB1' = ((`beta')*(exp((-`delta')*(`tau'))))*((-`lambda')*(-$ML_y8)^(`sigma')) if $ML_y8<0 & `task9'==1
      replace `yB1' = ((`beta')*(exp((-`delta')*(`tau'))))*((-`lambda')*(-$ML_y8)^(`sigma')) if $ML_y8<0 & `task10'==1
      replace `yB1' = ((`beta')*(exp((-`delta')*(`tau'))))*((-`lambda')*(-$ML_y8)^(`sigma')) if $ML_y8<0 & `task11'==1
      replace `yB1' = ((`beta')*(exp((-`delta')*(`tau'))))*((-`lambda')*(-$ML_y8)^(`sigma')) if $ML_y8<0 & `task12'==1
      replace `yB1' = ((`beta')*(exp((-`delta')*(`tau'))))*((-`lambda')*(-$ML_y8)^(`sigma')) if $ML_y8<0 & `task13'==1
      replace `yB1' = ((`beta')*(exp((-`delta')*(`tau'))))*((-`lambda')*(-$ML_y8)^(`sigma')) if $ML_y8<0 & `task14'==1
      replace `yB1' = ((`beta')*(exp((-`delta')*(`tau'))))*((-`lambda')*(-$ML_y8)^(`sigma')) if $ML_y8<0 & `task15'==1
      
      generate double `yB2' = .
      replace `yB2' = ( $ML_y9)^(`sigma') if $ML_y9>=0
      replace `yB2' = (-`lambda')*(-$ML_y9)^(`sigma') if $ML_y9<0
      
      gen double `euA' =.
      replace `euA' = (`prob1'*`yA1')+(`prob2'*`yA2') if `task0'==1
      replace `euA' = `yA1' if `task16'==1
      
      gen double `euB' =.
      replace `euB' = (`prob3'*`yB1')+(`prob4'*`yB2') if `task0'==1
      replace `euB' = `yB1' if `task16'==1
      
      replace Pchoice=0 if `euA'>`euB'
      replace Pchoice=1 if `euA'<`euB'
      
      generate double `euDiff' = `euB' - `euA'
      
      replace `lnf' = ln($cdf( `euDiff')) if $ML_y1==1
      replace `lnf' = ln($cdf(-`euDiff')) if $ML_y1==0
      
      replace ll=`lnf'
      
      }
      end
      I am almost certain that I need to edit out some of the tempvars e.g. some with the task# prefix because I can see in some lines such as replace `yB1' = ((`beta')*(exp((-`delta')*(`tau'))))*((-`lambda')*(-$ML_y8)^(`sigma')) if $ML_y8<0 & `task1'==1, I do not need some of the parameters beta and delta, which are time preference parameters. Could you please help getting me out of this one. I've tried editing this and always seem to make mistakes and the code keeps returning the annoying invalid syntax warning. I could even share with you the dataset should you be in a position to look at it.

      Comment


      • #4
        Stephen Mailu: You can apply -set trace on- which may help you identify part of your program that requires your attention. But if you haven't done so already, may I suggest that you read An Introduction to Stata Programming (by Kit Baum) or Maximum Likelihood Estimation with Stata (by William Gould and colleagues)? I'm sure it will be a very rewarding experience. You're looking at a very specific decision model (Prospect Theory and Quasi-Hyperbolic Discounting) and a highly specialised program which is tailored to data from an experiment with a very specific design. To be able to understand this program and edit it to suit your own requirements, you'll need to develop more familiarity with Stata's programming syntax than the average Stata user has.

        Comment

        Working...
        X