Announcement

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

  • Question about optimize() and non-linear flow constraints

    Hi everyone,

    Disclaimer: I have engaged in extensive googling but have not been able to find an answer to this question. Apologies if this has already been answered.

    I'm usually around the Stata forum but I'm trying to pick up Mata generally and optimize() in particular.

    What I want to accomplish is to reproduce a dynamic optimization problem described in Section 6.1.2 of the Book Adams, Clarke, Quinn (2015) Microeconometrics and MATLAB.

    I started with the simpler problem from Section 6.1.1 with linear constraints (flow equations) that has the following strcuture:
    1. Household has an endowment of W1 and must decide how much to consume each of T periods (the cake-eating problem).
    2. The household maximizes discounted utility over those T periods.
    3. The flow equation for capital is given by: kt+1=kt-ct
    4. This can be summarized in the following fashion: sum(ct)+kt+1=k1
    I managed to solve this problem for given parameter configurations with the following code:

    Code:
    // Rewrite optimization problem 6.1.1 Linear Flow Eqns, p.84 from Adams et al (2015) Microeconometrics for Matlab
    mata
    mata clear
    set matastrict off
    
    // Define flow utility equation
    function u(todo, numeric rowvector c, numeric scalar T, numeric scalar beta, u, g, H) {
        
        t = 1..T
        
        u = beta:^(t:-1) * log(c')
        
    }
    
    // Set params
    beta = 0.9
    T = 10
    k1 = 100
    c0 = J(1, T, 10)
    
    // Set constraints
    C = J(1, T, 1)
    c = k1
    
    // Set up optimization problem
    s = optimize_init()
    optimize_init_evaluator(s, &u())
    optimize_init_evaluatortype(s,"v0")
    optimize_init_params(s,c0)
    optimize_init_argument(s, 1, T)
    
    optimize_init_argument(s, 2, beta)
    optimize_init_constraints(s, (C,c))
    c_optim = optimize(s)
    c_optim
    sum(c_optim)
    end
    However, in a slightly modified version of this issue in Section 6.1.2 the flow constraints becomes(Cobb-Douglas-style) non-linear.

    That is, the flow constraints now is: kt+1=f(kt-ct, theta)= theta*(kt-ct)^alpha

    I am not able to come up with a solution for this modified flow equation. After a substantial amount of Googling it seems like that Mata cannot handle such constraints. Is this correct?

    Thanks for any insight.

    Best,
    Ulrich

    Edit: typo
    Last edited by Ulrich Wohak; 27 Jun 2022, 09:34.

  • #2
    Any chance I could ask Nick Cox or Andrew Musau to chip in? Would be much appreciated.

    Comment


    • #3
      As I understand it, only linear constraints are allowed with optimize(). I wouldn't say that you can't solve your problem with Mata, but not this way.

      Comment


      • #4
        Do the authors show how they implement the nonlinear constraint in their MATLAB code (like linearizing it by taking the logarithm or something)? Or do they accomplish via a feature that's built into MATLAB's optimizer? If Mata's optimize() doesn't have an analogue to whatever that is, then could you impose the constraint in the evaluator function, itself?

        Comment


        • #5
          A logarithm would turn you constrain into a linear constraint. That is a fairly common trick for this type of problems.​​
          ---------------------------------
          Maarten L. Buis
          University of Konstanz
          Department of history and sociology
          box 40
          78457 Konstanz
          Germany
          http://www.maartenbuis.nl
          ---------------------------------

          Comment

          Working...
          X