The operator + and the egen function rsum


What’s the difference between using the arithmetic operator + and the -egen- function rsum (equivalent to rowtotal)? Both return the row sum of the variables but treat missing values differently. For example, suppose we have the following data:



gen v3 = v1 + v2
The arithmetic operator + returns a missing value if one of the values is missing.

egen v4 = rsum(v1 v2)
The -egen- function rsum, on the other hand, treats missing values as zeros.

But, if the missing option is specified, rsum returns a missing value if all values in the varlist are missing.

egen v5 = rsum(v1 v2), missing


Leave a Reply