Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: st: nlsur quaids result depends on previous command


From   "Brian P. Poi" <[email protected]>
To   [email protected]
Subject   Re: st: nlsur quaids result depends on previous command
Date   Sat, 09 Jul 2011 12:12:52 -0400


On 07/09/2011 02:09 AM, Johannes Kutsam wrote:
Dear all,
(and especially Brian Poi),

I am estimating a QUAIDS demand system with nlsur quaids (POI 2008)
(http://www.stata-journal.com/article.html?article=st0029_1 )

I think found an error in either nlsur or quaids:
The coefficients are dependent on the command called before.

It can be reproduced using the example in sj8-4

webuse food
nlsur quaids @ w1 w2 w3 lnp1-lnp4 lnexp,ifgnls nequations(3) param(a1 a2 a3
b1 b2 b3 g11 g12 g13 g22 g23 g33 l1 l2 l3) nolog
nlsur quaids @ w1 w2 w3 lnp1-lnp4 lnexp,ifgnls nequations(1) param(a1 a2 a3
b1 b2 b3 g11 g12 g13 g22 g23 g33 l1 l2 l3) nolog
nlsur quaids @ w1 w2 w3 lnp1-lnp4 lnexp,ifgnls nequations(3) param(a1 a2 a3
b1 b2 b3 g11 g12 g13 g22 g23 g33 l1 l2 l3) nolog

Note that the 3 line with "nequations(1)" is of course wrong - because we
have 3 equations. BUT once this line was executed
The correct command  with "nequations(3) will yield wrong coefficients. (I
am not saying one should run wrongly specified systems...but it happens when
developing)

  I suspect that some variables are not initialized correctly in quaids that
could cause this problem.

When I clear the dataset and load it again I again get the same coefficents
as reported in sj8-4. So there is something temporarily saved by the call to
nlsur quaids that confuses
a subsequent call.


This is not a bug in -nlsur- or my QUAIDS code but an indication that if you write your own evaluator program and then call it incorrectly, -nlsur- could change your dataset. As long as you don't subsequently (re-)save your dataset to disk, there is no permanent harm to the data.

In this case, the variables w2 and w3 are being overwritten by -nlsurquaids.ado- in the second -nlsur- call. That's why your third call to -nlsur- doesn't work unless you reload the dataset.

Let's look at the second call to -nlsur- more carefully:

> nlsur quaids @ w1 w2 w3 lnp1-lnp4 lnexp,ifgnls nequations(1) param(a1 > a2 a3 b1 b2 b3 g11 g12 g13 g22 g23 g33 l1 l2 l3) nolog

You've told -nlsur- that there is one equation and hence one dependent variable. Therefore, -nlsur- is going to replace your first variable in the varlist with a temporary variable that your program will fill in with the fitted values of the dependent variable. Thus, -nlsur- is going to pass along the following varlist to your program:

   __00**** w2 w3 lnp1 lnp2 lnp3 lnp4 lnexp

where __00**** is a temporary variable, the last four characters of whose actual name are generated at run time.

Now the version of -nlsurquaids.ado- that we are using assumes there are three dependent variables that it is to fill in. So, -nlsurquaids.ado- is going to do -replace-s on the first three variables it is passed -- __00****, w2, and w3. The ado-file was written assuming the first three variables are tempvars it is to fill in, but because we called it via -nlsur- with the wrong number of equations specified, it's going to overwrite w2 and w3.

When I'm working on something like this, I do everything inside a do-file, and by habit I always reload the dataset at the top of my do-files unless I have a particular reason not to. That's why I've never come across this issue before. But it is definitely an issue to keep in mind.

   -- Brian Poi
   -- [email protected]


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index