Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

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

st: RE: combination of rolling and if

From   Nick Cox <[email protected]>
To   "'[email protected]'" <[email protected]>
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. 

[email protected] 

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

*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index