Announcement

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

  • Estimating CRRA Utility Function - Getting "variable __000000 not found"

    I am a rookie working with STATA, but am trying to estimate a CRRA Exponential Utility function using some sample test dataset.
    I am getting the error "variable __000000 not found"

    Can anyone help?


    clear

    input Choices P0left P1left P0right P1right prize0l prize1l prize0r prize1r
    1 1 0 0.50 0.50 1500 1500 1500 9000
    1 1 0 0.50 0.50 1500 1500 1500 9000
    1 1 0 0.50 0.50 1500 1500 1500 9000
    1 1 0 0.50 0.50 1500 1500 1500 9000
    1 1 0 0.50 0.50 1500 1500 1500 9000
    1 1 0 0.50 0.50 1500 1500 1500 9000
    0 1 0 0.50 0.50 1500 1500 1500 9000
    0 1 0 0.50 0.50 1500 1500 1500 9000
    0 1 0 0.50 0.50 1500 1500 1500 9000
    0 1 0 0.50 0.50 1500 1500 1500 9000
    0 1 0 0.50 0.50 1500 1500 1500 9000
    1 1 0 0.50 0.50 1500 1500 1500 9000
    end

    capture program drop ML_eut0
    program define ML_eut0

    args lnf r

    tempvar prob0l prob1l prob0r prob1r y0l y1l y0r y1r
    tempvar euL euR euDiff
    tempvar lnf euRatio lnf_eut lnf_pt p1 p2 f1 f2

    quietly {
    generate double `prob0l' = $ML_y2
    generate double `prob1l' = $ML_y3

    generate double `prob0r' = $ML_y4
    generate double `prob1r' = $ML_y5

    generate double `y0l' = ( $ML_y6 ) ^`r'
    generate double `y1l' = ( $ML_y7 ) ^`r'
    generate double `y0r' = ( $ML_y8 ) ^`r'
    generate double `y1r' = ( $ML_y9 ) ^`r'

    // generate `euL' = (`prob0l' * `y0l') + (`prob1l' * `y1l')
    // generate `euR' = (`prob0r' * `y0r') + (`prob1r' * `y1r')
    generate `euL' = (1 * `y0l') + (0 * `y1l')
    generate `euR' = (0.5 * `y0r') + (0.5 * `y1r')
    generate double `euDiff' = `euR' - `euL'

    replace `lnf' = ln(normal( `euDiff')) if $ML_y1==1
    replace `lnf' = ln(normal(-`euDiff')) if $ML_y1==0
    }
    end

    ml model lf ML_eut0 (r: Choices P0left P1left P0right P1right prize0l prize1l prize0r prize1r = ) if Choices~=., technique(nr) maximize
    Last edited by Ash Belur; 01 Jul 2024, 09:17.

  • #2
    Variable names such as __000000 starting with double underscore and followed by integers 000000, 000001, ... generally denote temporary variables.

    So, two questions:

    1. Exactly where does the error message arise, that is, after which command? You may need to

    Code:
    set trace on
    to see that.


    2. How are you defining your program? In essence, the code needs to be run all at once, not in chunks.

    Comment


    • #3
      Nick Cox - The first question / hint was very helpful. It indicated an error related to the second "replace lnf" command.
      This led me to find that my tempvar incorrectly included lnf as a temporary variable - which it should not have.

      Thanks - let's see how far I get on the real data.
      It did run all the way through and converged.

      Comment

      Working...
      X