Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Re: egen rowmin rowmax


From   Kit Baum <[email protected]>
To   [email protected]
Subject   st: Re: egen rowmin rowmax
Date   Sun, 5 Nov 2006 07:05:07 -0500

This should not be necessary.


rowtotal(varlist)
may not be combined with by. It creates the (row) sum of the
variables in varlist, treating missing as 0.

rowmin(varlist)
may not be combined with by. It gives the minimum value in varlist
for each observation (row). If all values in varlist are missing for
an observation, newvar is set to missing.


The egen rowtotal function will properly handle missings, and it properly handles varlists, including
the form firstvar-lastvar. (Remember that this is not the alpha order of your vars, but the data set order) Thus

webuse auto
egen tot = rowtotal(price-headroom)

will produce a variable with 74 obs. even though rep78 is in there. You refer to an egen function total(), which produces something quite different: a constant which is the sum of an exp. An exp of, say, price-headroom is exactly that: subtract headroom from price and sum it up. If MVs make the exp missing, then the sum will be missing. Perfectly logical: you get what you ask for. But you probably meant to use rowtotal.

Furthermore the rowmin function will properly pick out the minimum value, ignoring missings, unless all are
missing, so it should return zero for a row with all (or some) zeroes, greater than zero otherwise, if none of your rows contain all MVs.

Kit Baum, Boston College Economics
http://ideas.repec.org/e/pba1.html
An Introduction to Modern Econometrics Using Stata:
http://www.stata-press.com/books/imeus.html


On Nov 5, 2006, at 2:33 AM, statalist-digest wrote:


As it turns out, egen [var] = rowsum([varlist]) is equivalent to
egen [var] = total([varlist]).

My solution turned out to be to replace all of the zeros  in the seq*
cells with missings, then execute
egen byte minmath = rowmin(seq*) /*without the condition!*/
and add the following line of code:
replace minmath = 0 if minmath==.
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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