Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.

# Re: Re: st: nl command - error#130 expression too long

 From Nick Cox To statalist@hsphsun2.harvard.edu Subject Re: Re: st: nl command - error#130 expression too long Date Tue, 12 Feb 2013 15:37:33 +0000

```will not work. You may be seeking

local a = age[`i'] - 1

The syntax you are using is

local macname = exp

where exp is an expression. There is no support for [if] or [in] here;
whatever you want thereby should be done through subscripts.

Nick

On Tue, Feb 12, 2013 at 3:27 PM, Carlotta Schuster
<schuster.carlotta@gmail.com> wrote:

> Thank you Maarten. I have been exploring the ml command, with which I
> think I should be able to solve my problem. I am following Gould,
> Pitblado and Poi's Maximum Likelihood estimation with Stata, but I am
> unable to implement my problem correctly. I will try to describe the
> problem here.
>
> My model is the following (I omit subscripts hoping it is clear enough
> without them):
>
> Y = alpha + beta1*A(lambda)+beta2*X2+...+beta15*X15+ error
>
> Where y is a discrete choice variable and I want to estimate alpha,
> beta1,..., beta15 and LAMBDA. Here is where problem comes from, since
> A(lambda) is a non-linear function and I want to estimate lambda jointly
> with the rest of the parameters. If I set a particular value for lambda
> the model becomes a regular probit which I can easily estimate with
> Stata's probit command, but as I said, I also want to estimate lambda.
> In particular A(lambda) takes the following form:
>
> A(lambda) = sumatory(k=1 to k=age-1) weight(k,lambda)*Return_T-k
>
> And weight(k, lambda) is a non-linear function of lambda which also
> includes a sumatory and the age variable).
>
> Any ideas on how this could be program using the ml command?
>
> My tries so far have led me to the following program, where I create the
> A(lambda) variable inside the program using one of the parameters to be
> estimated.  But this does not work.
>
>
> capture program drop nlprobitlf
> program nlprobitlf
>   version 11
>   args todo b lnfj
>   tempvar w w_den N a
>
> local N = _N
> gen w_den = 0
> gen w = 0
> forvalues i = 1(1)`N' {
> local a = age-1 in `i'
> forvalues y = 1(1)`a'{
> replace w_den = w_den + (age-`y')^`b'[1,4] in `i'
> }
> forvalues z = 1(1)`a'{
> replace w = w + ((age-`z')^`b'[1,4])*rets`z'/w_den in `i'
> }
> }
>
>
> quietly generate double `xb' = `b'[1,1]+`b'[1,2]*w+`b'[1,3]*income
>
> quietly replace `lnfj' = lnnormal(`xb') if (\$ML_y1 == 1)
> quietly replace `lnfj' = lnnormal(-1*`xb') if (\$ML_y1 == 0)
>
>
> end
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/
```