Announcement

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

  • ml program question: right syntax to call parameters of an equation

    I want to display and use a component of an equation in my ml program, but I couldn't find the right syntax that would call it. lnsigu2 is modeled with a constant and x1, but all of the last three lines below display the same number. For example, display `lnsigu2:_cons' doesn't work to display lnsigu2 equation's constant's parameter during the maximization process. display _b[lnsigu2:_cons] doesn't work during the maximization. So what is the right syntax to display the constant in the lnsigu2 equation throughout the maximization process?


    Code:
    program mlprog
            args todo b lnf
    
            tempvar xb lnsigu2 lnsigw2
            mleval `xb' = `b', eq(1)
            mleval `lnsigu2' = `b', eq(2)
            mleval `lnsigw2' = `b', eq(3)
    
    .....
    
    display `lnsigu2'
    display `lnsigu2:_cons'
    display `lnsigu2:x1'
    
    .....
    
    end






  • #2
    Try instead ml maximize with the trace option. It will show the current vector of parameters during the optimization. See help maximize for more details.

    Comment


    • #3
      I know about the -set trace on- I used display command to see if I can call the component that I need to actually use in my model. So displaying isn't the ultimate goal. Having access to the parts of the equations in the model is the goal. In the maximization problem I need to use lnsigu2:_cons. How do you pull that information during the maximization process, say, to generate a variable equal to lnsigu2:_cons?

      Comment


      • #4
        Christophe was not refering to the set trace on command, but to the trace option in ml maximize. The latter will display at each iteration the vector of parameter estimates.

        Typically I would just use a separate equation for the constant and refer to it that way if I need access to the constant. This tends to lead to code that is easier to read, maintain, and debug. You will ofcourse need to add the nocons option for the rest of the equation, otherwise you will try to estimate two constants for the same equation.
        ---------------------------------
        Maarten L. Buis
        University of Konstanz
        Department of history and sociology
        box 40
        78457 Konstanz
        Germany
        http://www.maartenbuis.nl
        ---------------------------------

        Comment


        • #5
          Thanks. Right after I posted #3, I realized that Christophe meant the trace option and not the set trace command, but then I didn't edit my message because trace option doesn't solve my problem either, as you understood.

          I thought about setting a separate equation just for the constant of lnsigu2, but as you know, that would require additional changes in my estimation and post-estimation programs. If there is an easier way to somehow access that information, something like using the post-estimation _b[lnsigu2:_cons], I am for using that in the maximization program. I am almost sure that there is, I mean, there should be. If trace can show that information, there should be a way to access it in the program. I just don't know how.
          Last edited by Cyrus Levy; 30 May 2016, 04:05.

          Comment


          • #6
            Code:
            cap prog drop myml
            prog myml
            args todo b lnf tempvar xb lnsig mleval `xb' = `b' , eq(1) mleval `lnsigu' = `b' , eq(2) mat li `b' //scalar a = `b'[1,colnumb(`b',"eq1:_cons")] //scalar list a di `b'[1,colnumb(`b',"eq1:_cons")] di `b'[1,colnumb(`b',"sigma:_cons")] mlsum `lnf' = -0.5*(($ML_y1-`xb')/exp(`lnsigu'))^* 2-`lnsigu'
            end sysuse auto , clear ml model d0 myml ,(price = weight) /sigma ml check ml maximize
            Last edited by Christophe Kolodziejczyk; 30 May 2016, 05:10.

            Comment


            • #7
              ^ This!!! This is the reason why I love Stata. Amazing people on the forum! Thanks a million, Christophe!!! This works well and this is really the simplest solution that I've been looking for! Great!

              Comment

              Working...
              X