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 on April 23, and its replacement, statalist.org is already up and running.


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

Re: st: nl estimation: Error #130 Expression too long


From   "Brian P. Poi" <brian@poiholdings.com>
To   statalist@hsphsun2.harvard.edu, bne600@gmail.com
Subject   Re: st: nl estimation: Error #130 Expression too long
Date   Sat, 18 Jun 2011 09:30:43 -0400


On 06/18/2011 12:30 AM, Eugene Bempong Nyantakyi wrote:
I am trying to estimate a nonlinear least square equation but I keep on getting this error  saying "Expression too long" Here is the equation I am trying to estimate

nl (lgexp = log(exp({w_hat = 0.1 }*(z_hat + eta_hat)) - 1) + 1*{xb: ln_distance border n_island n_landlock legalsystem_same common_lang colonial cu fta religion_same eta_hat dum*}) if commcode == 1&  eta_hat != ., vce(cluster pairid)  no constant

dum* is a wildcard for  316 fixed effects. I have two sets of fixed effects exporter fixed effects  : dumexporter1 + dumexporter2 + dumexporter3 + ... + dumexporter158 and importer fixed effects: dumimporter1 + dumimporter2 + dumimporter3 + … + dumimporter158. so I use dum* to include all of them in the linear part of the equation. However when I include the dummies with dum* I get the error code that expression is too long and when I exclude them I get some results but I need to include them in the model. Can anybody help me with the programming. I really need help on this.


Eugene Kwasi
bne600@gmail.com


Eugene,

The solution to "expression to long" errors with -nl- is to write a function evaluator program to calculate your nonlinear function rather than using substitutable expressions. Function evaluator programs can be used to calculate arbitrarily long, complicated functions.

Try this example:

-----------------
clear all
sysuse auto

drop if missing(rep78)

areg mpg gear turn, absorb(rep78)

program nlfe

        version 11
        syntax varlist(min=3 max=3) if, at(name)
        local lhs : word 1 of `varlist'
        local x1  : word 2 of `varlist'
        local x2  : word 3 of `varlist'

	// Compute the first part of the function
        replace `lhs' = `at'[1,1]*`x1' + `at'[1,2]*`x2' `if'

        // Now loop over coefficients on rep78 indicators
        local atcnt = 3                 // First element of `at' for
                                        // rep78 params is the third.
        forvalues i = 1/5 {             // 5 levels of rep78
                replace `lhs' = `lhs' +                         ///
                                `at'[1, `atcnt']*(rep78 == `i') `if'
                local `++atcnt'
        }

end

nl fe @ mpg gear turn, nparam(7)
-----------------


-areg- includes a constant term in the model, but for simplicity I did not include one in the -nl- version; all the slope parameters will be identical, as will predicted values, though the R-squared will differ.

One question I have but do not have an answer for is whether there is an incidental parameters problem here. Except for linear regression and Poisson-type models (and maybe some obscure others), controlling for fixed effects by including dummy variables produces inconsistent results in the common case of large-N, fixed-T panel datasets. I do not know whether that is a problem here.

   -- Brian Poi
   -- brian@poiholdings.com
*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index