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, is already up and running.

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

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

From   "Brian P. Poi" <>
Subject   Re: st: nl command - error#130 expression too long
Date   Wed, 06 Feb 2013 09:45:05 -0600

On 02/06/2013 03:51 AM, Carlotta Schuster wrote:

Here is my whole code for the program (which fits the form of a function
evaluator program according to the help file for the nl command). After
the program I run the line I have at the end to call the program.
According to what I have read in the statalist this should work since
the function evaluator with the nl command should handle and arbitrarily
large number of variables. But I still get the #130 error of expression
too long.


program nlweight2, rclass

         version 11
         syntax varlist(min=1 max=300) if
         local istocks : word 1 of `varlist'
         local age_1 : word 2 of `varlist'
         local s2009 : word 3 of `varlist'
         local UNEMP : word 176 of `varlist'
         local PENS : word 177 of `varlist'

         return local eq "`istocks' = {A} +


nl weight2 : istocks age_1 s2009 age_2 s2008 age_3 s2007 age_4 s2006
age_5 s2005 age_6 s2004 age_7 s2003 age_8 s2002 age_9 s2001 age_10 s2000
age_11 s1999 age_12 s1998 age_13 s1997 age_14 s1996 age_15 s1995 age_16
s1994 age_17 s1993 age_18 s1992 age_19 s1991 age_20 s1990 age_21 s1989
age_22 s1988 age_23 s1987 age_24 s1986 age_25 s1985 age_26 s1984 age_27
s1983 age_28 s1982 age_29 s1981 age_30 s1980 age_31 s1979 age_32 s1978
age_33 s1977 age_34 s1976 age_35 s1975 age_36 s1974 age_37 s1973 age_38
s1972 age_39 s1971 age_40 s1970 age_41 s1969 age_42 s1968 age_43 s1967
age_44 s1966 age_45 s1965 age_46 s1964 age_47 s1963 age_48 s1962 age_49
s1961 age_50 s1960 age_51 s1959 age_52 s1958 age_53 s1957 age_54 s1956
age_55 s1955 age_56 s1954 age_57 s1953 age_58 s1952 age_59 s1951 age_60
s1950 age_61 s1949 age_62 s1948 age_63 s1947 age_64 s1946 age_65 s1945
age_66 s1944 age_67 s1943 age_68 s1942 age_69 s1941 age_70 s1940 age_71
s1939 age_72 s1938 age_73 s1937 age_74 s1936 age_75 s1935 age_76 s1934
age_77 s1933 age_78 s1932 age_79 s1931 age_80 s1930 logincome
logincomesq children childrensq logliquidassets logliquidassetssq
retired college married financial_sector SMC_pc GPD_pc GDP_pc INF UNEMP
PENS, nolog;


You are correct that -nl- can handle rather large models when using the function evaluator program (FEP) version.  However, your program is based on the programmed substitutable expression (PSE) version of -nl-.

If you type in

. help nl

and go just beyond halfway down, you'll see a section titled "Some commonly used models."  -nl- has pre-programmed models for various forms of exponential, logistic, and Gompertz regression.  The PSE version of -nl- makes implementing those types of models easy.  The models themselves are small, but the PSE version of -nl- lets us include code to compute good starting values.  PSE models are fitted with -nl- by typing

. nl <name> : ...

where <name> is the name of your PSE.

Instead, you want to use the FEP version of -nl-.  About three-quarters of the way down in the help file for -nl- you will find information about function evaluator programs, and of course the reference manual entry has a more-detailed discussion.  FEP models are fitted by typing

. nl <fname> @ ...

where <fname> is the name of your FEP.  Notice the "@" sign versus a ":" for the PSE version.

To avoid the "expression too long" error, use temporary variables to build up intermediate results.  Then you can compute the final value of your function combining those results.  We do that in the FEP examples in the help file and reference manual.  Plus, that makes debugging programs much easier.

I hope this helps.

   -- Brian Poi

*   For searches and help try:

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