[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
st: Re: operate on allbut
--On Monday, September 23, 2002 2:33 -0400Caleb wrote:
I want to collapse a large number of variables by tract, i.e.
. collapse (sum) _all, by(tract)
Naturally, stata complains that tract is included in _all:
tract may not be both target and by()
Any clever way around that? Perhaps defining a macro that excludes one
name? I could type it all in, but this procedure has to be repeated for
many datafiles with different varlists (but which include tract).
There may (probably) be a better way to do this, but...
* allbut varname -> r(allbut) contains all vars but that one
* cfb 23sep2002
program define allbut,rclass
local allvar `r(allvars)'
local allbut : subinstr local allvar "`varlist'" "",word
return local allbut `"`allbut'"'
program define _allvars,rclass
return local allvars `varlist'
. allbut med
. collapse (sum) `r(allbut)',by(med)
Could readily be extended to allow for multiple items in the bylist.
Christopher F Baum, Boston College Economics, Chestnut Hill MA 02467 USA
* For searches and help try: