Announcement

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

  • Looking for a Stata version of lsqlin MATLAB command

    Hello,

    I went into this on a different post, but I'm still having difficulty with my Stata program, so I thought I would try a different approach.

    Currently I complete a minimization problem in MATLAB using the command lsqlin (https://www.mathworks.com/help/optim/ug/lsqlin.html). I've made the equivalent matrices and upper and lower bounds in Stata with mata, but I'm struggeling to execute the rest of the program. I've tried using optimize, but I still keep getting a conformability error (3200). I've pasted my code below.

    Is there an equivalent Stata command for MATLAB's lsqlin command? Or is my optimize code just wrong?

    Code:
    mata

    X=st_data(., "XRegE XRegM XRegS XRegW")
    Xt=X' /* transpose */

    omegadiag=st_data(., "omegadiag")
    omega=diag(omegadiag)

    C=Xt*omega
    D=C*X

    diag100=blockdiag(D,blockdiag(D,blockdiag(D,blockd iag(D,blockdiag(D,blockdiag(D,blockdiag(D,blockdia g(D,blockdiag(D,blockdiag(D,blockdiag(D,blockdiag( D,blockdiag(D,blockdiag(D,blockdiag(D,blockdiag(D, blockdiag(D,blockdiag(D,blockdiag(D,blockdiag(D,bl ockdiag(D,blockdiag(D,blockdiag(D,blockdiag(D,bloc kdiag(D,blockdiag(D,blockdiag(D,blockdiag(D,blockd iag(D,blockdiag(D,blockdiag(D,blockdiag(D,blockdia g(D,blockdiag(D,blockdiag(D,blockdiag(D,blockdiag( D,blockdiag(D,blockdiag(D,blockdiag(D,blockdiag(D, blockdiag(D,blockdiag(D,blockdiag(D,blockdiag(D,bl ockdiag(D,blockdiag(D,blockdiag(D,blockdiag(D,bloc kdiag(D,blockdiag(D,blockdiag(D,blockdiag(D,blockd iag(D,blockdiag(D,blockdiag(D,blockdiag(D,blockdia g(D,blockdiag(D,blockdiag(D,blockdiag(D,blockdiag( D,blockdiag(D,blockdiag(D,blockdiag(D,blockdiag(D, blockdiag(D,blockdiag(D,blockdiag(D,blockdiag(D,bl ockdiag(D,blockdiag(D,blockdiag(D,blockdiag(D,bloc kdiag(D,blockdiag(D,blockdiag(D,blockdiag(D,blockd iag(D,blockdiag(D,blockdiag(D,blockdiag(D,blockdia g(D,blockdiag(D,blockdiag(D,blockdiag(D,blockdiag( D,blockdiag(D,blockdiag(D,blockdiag(D,blockdiag(D, blockdiag(D,blockdiag(D,blockdiag(D,blockdiag(D,bl ockdiag(D,blockdiag(D,blockdiag(D,blockdiag(D,D))) )))))))))))))))))))))))))))))))))))))))))))))))))) ))))))))))))))))))))))))))))))))))))))))))))))

    L=blockdiag(D,blockdiag(D,blockdiag(D,blockdiag(D, blockdiag(D,blockdiag(D,blockdiag(D,blockdiag(D,bl ockdiag(D,blockdiag(D,blockdiag(D,blockdiag(D,bloc kdiag(D,blockdiag(D,blockdiag(D,blockdiag(D,blockd iag(D,blockdiag(D,blockdiag(D,blockdiag(D,blockdia g(D,blockdiag(D,blockdiag(D,blockdiag(D,blockdiag( D,blockdiag(D,blockdiag(D,blockdiag(D,blockdiag(D, blockdiag(D,blockdiag(D,blockdiag(D,blockdiag(D,bl ockdiag(D,diag100))))))))))))))))))))))))))))))))) )
    B=vec(C)

    /*L (536 x 536 matrix) is equivalent to MATLAB's C in the link provided above and B (536 x 1 matrix) is equivalent to MATLAB's d in the link provided above */

    void weights(todo, p, L, B, W, g, H)
    {
    W=L*p - B
    }

    S = optimize_init()
    optimize_init_which(S,"min")
    optimize_init_evaluator(S, &weights())
    optimize_init_evaluatortype(S, "gf2")
    optimize_init_argument(S,1,L)
    optimize_init_argument(S,2,B)
    optimize_init_params(S, 0)
    p=optimize(S)
Working...
X