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: nl command - error#130 expression too long


From   "Brian P. Poi" <[email protected]>
To   [email protected]
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.

Thanks.




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'
<snip>
         local UNEMP : word 176 of `varlist'
         local PENS : word 177 of `varlist'

         return local eq "`istocks' = {A} +
{B}*((`age_1'^{lambda}*`s2009'+`age_2'^{lambda}*`s2008'+`age_3'^{lambda}
*`s2007'+`age_4'^{lambda}*`s2006'+`age_5'^{lambda}*`s2005'+`age_6'^{lamb
da}*`s2004'+`age_7'^{lambda}*`s2003'+`age_8'^{lambda}*`s2002'+`age_9'^{l
ambda}*`s2001'+`age_10'^{lambda}*`s2000'+`age_11'^{lambda}*`s1999'+`age_
12'^{lambda}*`s1998'+`age_13'^{lambda}*`s1997'+`age_14'^{lambda}*`s1996'
+`age_15'^{lambda}*`s1995'+`age_16'^{lambda}*`s1994'+`age_17'^{lambda}*`
s1993'+`age_18'^{lambda}*`s1992'+`age_19'^{lambda}*`s1991'+`age_20'^{lam
bda}*`s1990'+`age_21'^{lambda}*`s1989'+`age_22'^{lambda}*`s1988'+`age_23
'^{lambda}*`s1987'+`age_24'^{lambda}*`s1986'+`age_25'^{lambda}*`s1985'+`
age_26'^{lambda}*`s1984'+`age_27'^{lambda}*`s1983'+`age_28'^{lambda}*`s1
982'+`age_29'^{lambda}*`s1981'+`age_30'^{lambda}*`s1980'+`age_31'^{lambd
a}*`s1979'+`age_32'^{lambda}*`s1978'+`age_33'^{lambda}*`s1977'+`age_34'^
{lambda}*`s1976'+`age_35'^{lambda}*`s1975'+`age_36'^{lambda}*`s1974'+`ag
e_37'^{lambda}*`s1973'+`age_38'^{lambda}*`s1972'+`age_39'^{lambda}*`s197
1'+`age_40'^{lambda}*`s1970'+`age_41'^{lambda}*`s1969'+`age_42'^{lambda}
*`s1968'+`age_43'^{lambda}*`s1967'+`age_44'^{lambda}*`s1966'+`age_45'^{l
ambda}*`s1965'+`age_46'^{lambda}*`s1964'+`age_47'^{lambda}*`s1963'+`age_
48'^{lambda}*`s1962'+`age_49'^{lambda}*`s1961'+`age_50'^{lambda}*`s1960'
+`age_51'^{lambda}*`s1959'+`age_52'^{lambda}*`s1958'+`age_53'^{lambda}*`
s1957'+`age_54'^{lambda}*`s1956'+`age_55'^{lambda}*`s1955'+`age_56'^{lam
bda}*`s1954'+`age_57'^{lambda}*`s1953'+`age_58'^{lambda}*`s1952'+`age_59
'^{lambda}*`s1951'+`age_60'^{lambda}*`s1950'+`age_61'^{lambda}*`s1949'+`
age_62'^{lambda}*`s1948'+`age_63'^{lambda}*`s1947'+`age_64'^{lambda}*`s1
946'+`age_65'^{lambda}*`s1945'+`age_66'^{lambda}*`s1944'+`age_67'^{lambd
a}*`s1943'+`age_68'^{lambda}*`s1942'+`age_69'^{lambda}*`s1941'+`age_70'^
{lambda}*`s1940'+`age_71'^{lambda}*`s1939'+`age_72'^{lambda}*`s1938'+`ag
e_73'^{lambda}*`s1937'+`age_74'^{lambda}*`s1936'+`age_75'^{lambda}*`s193
5'+`age_76'^{lambda}*`s1934'+`age_77'^{lambda}*`s1933'+`age_78'^{lambda}
*`s1932'+`age_79'^{lambda}*`s1931'+`age_80'^{lambda}*`s1930')/(`age_1'^{
lambda}+`age_2'^{lambda}+`age_3'^{lambda}+`age_4'^{lambda}+`age_5'^{lamb
da}+`age_6'^{lambda}+`age_7'^{lambda}+`age_8'^{lambda}+`age_9'^{lambda}+
`age_10'^{lambda}+`age_11'^{lambda}+`age_12'^{lambda}+`age_13'^{lambda}+
`age_14'^{lambda}+`age_15'^{lambda}+`age_16'^{lambda}+`age_17'^{lambda}+
`age_18'^{lambda}+`age_19'^{lambda}+`age_20'^{lambda}+`age_21'^{lambda}+
`age_22'^{lambda}+`age_23'^{lambda}+`age_24'^{lambda}+`age_25'^{lambda}+
`age_26'^{lambda}+`age_27'^{lambda}+`age_28'^{lambda}+`age_29'^{lambda}+
`age_30'^{lambda}+`age_31'^{lambda}+`age_32'^{lambda}+`age_33'^{lambda}+
`age_34'^{lambda}+`age_35'^{lambda}+`age_36'^{lambda}+`age_37'^{lambda}+
`age_38'^{lambda}+`age_39'^{lambda}+`age_40'^{lambda}+`age_41'^{lambda}+
`age_42'^{lambda}+`age_43'^{lambda}+`age_44'^{lambda}+`age_45'^{lambda}+
`age_46'^{lambda}+`age_47'^{lambda}+`age_48'^{lambda}+`age_49'^{lambda}+
`age_50'^{lambda}+`age_51'^{lambda}+`age_52'^{lambda}+`age_53'^{lambda}+
`age_54'^{lambda}+`age_55'^{lambda}+`age_56'^{lambda}+`age_57'^{lambda}+
`age_58'^{lambda}+`age_59'^{lambda}+`age_60'^{lambda}+`age_61'^{lambda}+
`age_62'^{lambda}+`age_63'^{lambda}+`age_64'^{lambda}+`age_65'^{lambda}+
`age_66'^{lambda}+`age_67'^{lambda}+`age_68'^{lambda}+`age_69'^{lambda}+
`age_70'^{lambda}+`age_71'^{lambda}+`age_72'^{lambda}+`age_73'^{lambda}+
`age_74'^{lambda}+`age_75'^{lambda}+`age_76'^{lambda}+`age_77'^{lambda}+
`age_78'^{lambda}+`age_79'^{lambda}+`age_80'^{lambda}))+{C}*`logincome'+
{beta2}*`logincomesq'+{beta3}*`children'+{beta4}*`childrensq'+{beta5}*`l
ogliquidassets'+{beta6}*`logliquidassetssq'+{beta7}*`retired'+{beta8}*`c
ollege'+{beta9}*`married'+{beta10}*`financial_sector'+{beta11}*`SMC_pc'+
{beta12}*`GPD_pc'+{beta13}*`GDP_pc'+{beta14}*`INF'+{beta15}*`UNEMP'+{bet
a16}*`PENS'"


end




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;
*

Carlotta,

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
   -- [email protected]

*
*   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/


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