.- help for ^expr^ and ^exprcmd^ (STB-39: ip19) .- Expansion of expressions in commands ------------------------------------ ^expr^ [, ^nod^etail]: cmd expr-list [^if^ exp] [^in^ range] [weight] [^using^ filename] [^,^ options] ^exprcmd^ [, ^nod^etail] Description ----------- ^expr^ is a prefix command that permits a list of expressions expr-list instead of a list of variables in the command ^cmd^. Expressions should be seperated by white space; thus, expressions may not contain embedded spaces. ^expr^ only supports "regular" Stata commands (see below). ^exprcmd^ switches on expression expansion for all subsequent commands. In the command prompt, the string ^(expr)^ is displayed. To suppress expression expansion in a command, prefix it with a period (^.^). To switch expression expansion, issue the period ^.^ as a single command. Options ------- ^detail^ specifies that the expressions and the expanded command are displayed. Technical remarks ----------------- The "regular" syntax of Stata commands is cmd varlist [if expr] [in range] [weight], options Due to limitations of the Stata parser, the command string may not contain double quotes. ^expr^ parses the expr-list on spaces, it then verifies whether a token can be interpreted as a varlist (using ^unabbrev^), and otherwise tries to interpret the token as an expression. Thus, ^x1-x2^ is interpreted as the list of variables between ^x1^ and ^x2^, not as the arithmetic difference between the variables ^x1^ and ^x2^. To fool ^expr^ in adopting the second interpretation, use ^x1-1*x2^ or ^x1+(-x2)^. Note that this ambiguity in Stata syntax would become even larger with my "enhanced" varlist (see ^unabrev2^) where ^x1*x2^ would be interpreted as the list of variables with ^names^ that begin with ^x1^ and end with ^x2^, and not as the product of ^x1^ and ^x2^. ^expr^ generates variables _Expr, n=0,1,..., for non-atomic expressions. These variables are properly labeled using the defining expressions and are kept in the data so that, e.g., post-estimation commands such as ^predict^, ^test^, ^lfit^ etc should work properly. After estimation commands, you may want to use ^diest^ for more understandable output. All variables named _Expr are silently dropped by ^expr^. Examples -------- . ^expr: summ x1 x1^^2 x1^^3+sin(x2/x3)^ . ^expr: summ x1^ (^expr^ has no effect here) . ^expr: reg y x1 ln(abs(x1)), nocons^ . ^exprcmd^ (switch on expression expansion) (expr) . ^summ x1 x1^^2 x1^^3+sin(x2/x3)^ (expr) . ^reg y x1 ln(abs(x1)), nocons^ . ^.^ (end expression expansion) Author ------ Jeroen Weesie Utrecht University Netherlands email: weesie@@weesie.fsw.ruu.nl Also See -------- STB: STB-39 ip19 Manual: [U] 20 Functions and expressions On-line: help for @exp@, @diest@