# st: RE: st : Problem with nlcom (expression too long)

 From "Gustavo Sanchez" To Subject st: RE: st : Problem with nlcom (expression too long) Date Mon, 25 Feb 2008 12:05:55 -0600

```Valerie [Valerie(dot)Orozco(at)toulouse(dot)inra(dot)fr] asked:

>> I try to estimate a lot of coefficients from a first estimation. My
program
>> consists in writing all the coefficients I want in some macros (local)
and run
>> the nlcom command with only one big macro.
>> The problem of length comes from the fact that some coefficients I have
to
>> estimate are also combinations of coefficients I estimate in the same
>> -nlcom- command.
>> ...
>> The problem is that for some coefficients I want the expression is quite
long...
>> So Stata stops tells me:expression too long r(130);
>>
>> How can I have all my coefficients in one matrix e(b) and e(V) doing
several
>> nlcom? (in order to have smaller expression using the coefficients
obtained in
>> a first nlcom...)
>> If someone has an idea:

We asked privately for Valerie's file, in order to check the problem with
her
actual data.

There is a limit of 500 dyadic operators or 225 pairs of nested
parentheses that can be used in an expression in Stata. One of
Valerie's equations is hitting this limit; therefore, she needs
to split this expression into smaller pieces. This can be tricky in the
context of -nlcom-, so let us show how it can be done.

Let's assume that we have the following code:

sysuse auto, clear
qui regress mpg price rep dis for

nlcom  (norm(_b[price]* _b[rep]) + exp(_b[dis]*_b[for]))

We will obtain the following output:

.  sysuse auto, clear
(1978 Automobile Data)

.   qui regress mpg price rep dis for

.
.   nlcom  (norm(_b[price]* _b[rep]) + exp(_b[dis]*_b[for]))

_nl_1:  norm(_b[price]* _b[rep]) + exp(_b[dis]*_b[for])

----------------------------------------------------------------------------
mpg |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-----------+----------------------------------------------------------------
_nl_1 |   1.544752   .0822579    18.78   0.000     1.380423    1.709081
----------------------------------------------------------------------------

Here, -nlcom- uses the delta method to compute the variance of this
expression, and uses this variance to compute the confidence interval. Now,
let's pretend that the expression is too long. If we split the expression in
two parts, and use each part in one equation, -nlcom- would compute a
covariance matrix for the corresponding two expressions. If, in addition, we
use the option -post-, the new values and their covariance would be posted
as
current results, and, therefore, we would be able to use -nlcom- again to
obtain
the solution for the original problem.

nlcom (a1:norm(_b[price]* _b[rep])) (a2:exp(_b[dis]*_b[for])), post
nlcom _b[a1] + _b[a2]

Here is the output:

.  nlcom (a1:norm(_b[price]* _b[rep])) (a2:exp(_b[dis]*_b[for])), post

a1:  norm(_b[price]* _b[rep])
a2:  exp(_b[dis]*_b[for])

----------------------------------------------------------------------------
mpg |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-----------+----------------------------------------------------------------
a1 |   .4999275   .0001062  4705.45   0.000     .4997152    .5001397
a2 |   1.044825   .0822261    12.71   0.000     .8805589     1.20909
----------------------------------------------------------------------------

.   nlcom _b[a1] + _b[a2]

_nl_1:  _b[a1] + _b[a2]

----------------------------------------------------------------------------
|      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-----------+----------------------------------------------------------------
_nl_1 |   1.544752   .0822579    18.78   0.000     1.380423    1.709081
----------------------------------------------------------------------------

Isabel Canette 					Gustavo Sanchez
icanette(at)stata(dot)com			gsanchez(at)stata(dot)com
StataCorp						StataCorp

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
```