Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: RE: xcollapse, multiple ifs


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: xcollapse, multiple ifs
Date   Fri, 27 Mar 2009 15:47:27 -0000

-xcollapse- is a user-written command by Roger Newson from SSC or his
own website. Please specify where user-written commands you refer to
come from. 

The answer I think is No: at most one -if- condition. But what I guess
you want is easily done otherwise, and -collapse- looks enough. For
example, 

gen decade = floor(year/10) 

collapse x, by(decade) 

I assume that you don't really want to omit years like 1980. -ceil()-
could be what you want instead of -floor()-. 

Nick 
[email protected] 

richard boylan

Is there any way to have different "if statements" with the command
xcollapse?

I tried to do

xcollapse (mean) m1 = x if year > 1970 & year <1980 (mean) m2 = x if
year > 1980 & year < 1990...

but I got an error message.

One way to get around this problem is to just define new variables so

x1 = x if  year > 1970 & year < 1980
x2 = x if  year > 1980 & year < 1990

and then

xcollapse (mean) x1 x2...

but was wondering if there was a better way of doing this.

*
*   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