Stata 15 help for expressions


[U] 13 Functions and expressions


Algebraic and string expressions are specified in a natural way using the standard rules of hierarchy. You may use parentheses freely to force a different order of evaluation.

For example:

. generate new = myv+2/oth

is interpreted as

. generate new = myv+(2/oth)

If you wanted (myv+2)/oth, you could type

. generate new = (myv+2)/oth

Expressions are found in several places in the Stata language; see language. The "=exp" language element is demonstrated above with the generate command. The "if exp" language element is another place where expressions are allowed. Almost all Stata commands allow the "if exp". For instance, in

. summarize mrg dvc if region=="West" & mrg>.02

the region=="West" & mrg>.02 is a logical expression.


. sysuse auto . generate weight2 = weight^2

. webuse census12, clear . summarize marriage_rate divorce_rate if region == "West" & marriage_rate > .015

. drop _all . set obs 10 . generate x = _n^3 - 10*_n^2 + 5*_n . generate z = x + 50*rnormal()

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