Announcement

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

  • MLE estimation with constrained parameter

    Dear users,

    I am trying to perform a MLE with a constrained parameter, and I would like to constrain beta2 = 1.3. However, when I run the code, it treats beta2 as an unconstrained parameter.

    Here is my code:

    Code:
    set seed 11
    clear
    set obs 500
    matrix define means = (0,0)
    matrix define covar = (1, 0.5 \ 0.5, 1)
    drawnorm x z, means(means) cov(covar)
    gen y=1+1.2*x+1.5*z+2*rnormal()
    
    mlexp (-0.5*ln({sigma2})-0.5*(y - {beta0}-  x*{beta1} - z*{beta2=1.3})^2/{sigma2})

  • #2
    Code:
    set seed 11
    clear
    set obs 500
    matrix define means = (0,0)
    matrix define covar = (1, 0.5 \ 0.5, 1)
    drawnorm x z, means(means) cov(covar)
    gen y=1+1.2*x+1.5*z+2*rnormal()
    
    
    constraint define 1 /beta2 = 1.3 
    mlexp (-0.5*ln({sigma2})-0.5*(y - {beta0}-  x*{beta1} - z*{beta2})^2/{sigma2}), constraint(1)
    Your code specifies that the initial value for beta2 to be passed to the optimisation engine is 1.3.

    Comment


    • #3
      Thanks, Andrea Discacciati. I used your code, but it returned: "constraints not allowed".

      Comment


      • #4
        It works with Stata v 15.1.

        Which Stata version do you have?
        If Stata 14, try with
        Code:
        constraint define 1 _b[/beta2] = 1.3

        Comment


        • #5
          Yes, it is the Stata 14. Unfortunately, it is still not working.

          Thanks for the help, anyway.

          Comment


          • #6
            Ok, last try:

            Code:
            constraint define 1  _b[beta2:_cons] = 1.3

            Comment

            Working...
            X