Statalist


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

Re: st: Collapse All


From   Johannes Geyer <[email protected]>
To   [email protected]
Subject   Re: st: Collapse All
Date   Mon, 8 Sep 2008 10:11:47 +0200

Nikhi wrote:

> Is there a way to get all (_all) except for one of the variables?

To my mind come two easy solutions:

- to use "if" and loop through the levels of your categorical variable:

********************************
sysuse auto, clear
drop make
forvalues i = 0/1 {
preserve
collapse _all if foreign == `i'
save c:\temp\collapse`i', replace
if `i' == 1 {
append using c:\temp\collapse0.dta
save c:\temp\collapse01, replace
}
restore
}
********************************

- or have a look at the command "ds"

type 
findit ds

ds saves a varlist in the macro r(varlist) and  you can specify a negative 
criterium,
e.g.

********************************
sysuse auto, clear
drop make
ds for, not
collapse `r(varlist)', by(foreign)
********************************

regards,

Johannes






*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   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