Statalist


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

st: running collapse


From   "Ashim Kapoor" <ashimkapoor@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   st: running collapse
Date   Fri, 21 Nov 2008 12:41:24 +0530

Hello everyone,

I wish to create a " running collapse" . I wonder if this is even the
right command to do this. Here is what I want :-

I have a dataset

Month  Returns
1               .5
1                .6
1                .7
2            etc
2
2
3
3
3
4
4
4
5
5
5
6                  1
6
6

So the command:

collapse (mean) returns, by (month) would generate the mean monthly returns.

But suppose now I want 2 monthly returns   so for February I want the
mean over Jan and Feb, for March I would want the mean over Feb and
March etc.

Now I can do : --
sort month
egen j=group(month)
replace j=j-1 if mod(j,2)==0

THIS DOES group 2 months together but it does not give me a "running
group". For example Jan - Feb would be one group and the next one will
be Mar-April instead of being Feb-Mar.

Has someone dealt with this ?

Thank you,
Ashim.
*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index