Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


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

st: RE: combination of rolling and if


From   Nick Cox <n.j.cox@durham.ac.uk>
To   "'statalist@hsphsun2.harvard.edu'" <statalist@hsphsun2.harvard.edu>
Subject   st: RE: combination of rolling and if
Date   Tue, 13 Dec 2011 21:28:56 +0000

-if- in general selects observations and then does something with those observations alone. 

It does not try to interpret what you really want or extend any operation beyond the observations selected. 

I would be surprised if -rolling- were different, but (disclaimer) I've never studied it carefully. 

With Kit Baum I sorted out these questions to our mutual satisfaction in -mvsumm- (SSC), which has Remarks addressed to precisely this question. 

-rolling- came rolling along later, as I recall, and it (necessarily) is pitched much more generally and to allow many more kinds of result. 

But your example shows an interest in moving averages only. I guess you would find -mvsumm- or -tssmooth- more straightforward.  

In general, with -rolling- or anything else rolling -if- and/or -in- should only be used to exclude observations which should never participate in _any_ of the operations specified. More commonly, you are interested in some _results_ only, but it is usually easiest to calculate every average in sight and then just ignore what you don't want. 

Nick 
n.j.cox@durham.ac.uk 

qing ye

I am a bit confused with combining the rolling and if.

what does the following commend do?

I have monthly panel data, variables are

stock, date, return, ST


for the following code
rolling mean=r(mean), windows (12): sum return if ST=1, detail

Did it, for every month, take observations whose 'ST'=1 and then
calculate mean return for this group of stocks over the next 12
months? This is what I wanted to do.

Or, did it, for every month, take all the observations in the next 12
months, and calculate mean returns of all the observation for which
'ST'==1?


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