Statalist


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

RE: st: RE: xcollapse, multiple ifs


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: RE: xcollapse, multiple ifs
Date   Sun, 29 Mar 2009 17:14:56 +0100

The complaint here appears to be that my code "does not work" because the real question is not what Richard asked previously.  

In that case I guess that Richard tried to modify the code but since he does not say what he tried it is difficult to comment on his solution. 

But Richard appears to want several variables each to be averaged by decade and the -collapse- solution to get those summaries is just an extension of the code I gave earlier. (I guess decades are to be disjoint despite the overlapping labels such as 1960-1970 and 1970-1980.) 

I don't use -listtex- but similar comments apply to advice on that command. 

Nick 
[email protected] 

richard boylan

Thanks.

This suggestion does not work since what I am trying to do is make a table using
listtex  ( user-written command by Roger Newson from SSC!) that looks like this

                    1960-1970                            1970-1980
                          1980-1990

variable x      mean x over 1960-1970          mean x over 1970-1980
          mean x over 1980-1990
variable y      mean y over 1960-1970          mean y over 1970-1980
          mean y over 1980-1990
variable z       ....
...

On Fri, Mar 27, 2009 at 10:47 AM, Nick Cox <[email protected]> wrote:

> -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()-.

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