Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, is already up and running.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: mata optimize problem

From   "Michael Ralph M. Abrigo" <>
Subject   st: mata optimize problem
Date   Sat, 3 Jul 2010 14:08:35 +0800

Good day statalisters!
I am practically new in programming, especially in Mata. I'm trying to
implement Lambert, Brown and Florax's (2010) poisson spatial lag model
("A two-step estimator for a spatial lag model for counts: Theory,
small sample performance and an application", Urban and Regional
Economics) in Stata using full-information ML (instead of the two-step
LIML). However, I got stuck because of a conformability error which I
cannot trace (I was able to generate the matrices interactively using
ad hoc values). I was hoping I can do the FIML first before I venture
to their two-step estimator.
Any hint will be greatly appreciated.
Below is my code and the error messages.
drop _all
** (1) Set version; Open file
version 11.0
webuse "dollhill3.dta", clear
** (2) Generate constant; Local variables
gen cons = 1
local y deaths
local xlist smokes pyears cons
** (3) Generate weight matrix
sort pyears
gen xcoor = _n
gen ycoor = _n
spwmatrix gecon xcoor ycoor, wname(W) wtype(bin) ///
   dband(0 1000) rowstand mata replace
** (4) Optimize using Mata
  void spmlpoisson (
    real scalar todo,
real rowvector rho_b,
real colvector lndensity,
real matrix g,
real matrix H)
      external y, X, W, I
 transmorphic A_inv
 real colvector Xb_sar, mu_sar
 real rowvector b
 real scalar rho
      rho_b = rho, b
A_inv = cholinv(I - rho * W)
Xb_sar = A_inv * X * b'
        mu_sar = exp(Xb_sar)
lndensity = (y :* Xb_sar) - mu_sar - lnfactorial(y)
  st_view(y = ., ., "`y'")
  st_view(X = ., ., tokens("`xlist'"))
  fh = fopen("W", "r")
    W = fgetmatrix(fh)
  I = I(cols(W))
  S = optimize_init()
  optimize_init_evaluator(S, &spmlpoisson())
  optimize_init_which(S, "max")
  optimize_init_evaluatortype(S, "d0")
  optimize_init_params(S, J(1, cols(X) + 1, 0))
  rho_b = optimize(S)
                       *:  3200  conformability error
           spmlpoisson():     -  function returned error
      opt__calluser0_d():     -  function returned error
      opt__d0_calluser():     -  function returned error
    deriv__call1user_d():     -  function returned error
 _deriv__compute_value():     -  function returned error
                _deriv():     -  function returned error
       opt__eval_nr_d0():     -  function returned error
             opt__eval():     -  function returned error
opt__looputil_iter0_common():     -  function returned error
opt__looputil_iter0_nr():     -  function returned error
          opt__loop_nr():     -  function returned error
              optimize():     -  function returned error
                 <istmt>:     -  function returned error


"I am most anxious for liberties for our country... but I place as a
prior condition the education of the people so that our country may
have an individuality of its own and make itself worthy of
liberties... " Jose Rizal,1896

*   For searches and help try:

© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index