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

# Re: st: RE: combination of rolling and if

 From qing ye To statalist@hsphsun2.harvard.edu Subject Re: st: RE: combination of rolling and if Date Wed, 14 Dec 2011 05:51:50 +0800

```hi, Thanks for this!

I have checked the -tssmooth-, not exactly sure what it does as I
don't know anything about smooth.  But I probably do not need it as I
only want to select a group of stocks every month and calculate their
mean returns over the next 12 months.

is there anyway I can realize this using rolling? Rolling seems to be
the only command I can think of in this context.

"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. " -- You probably told me what to do, but
I am still cannot get it.

Thanks
Qing

On 14 December 2011 05:28, Nick Cox <n.j.cox@durham.ac.uk> wrote:
> -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/

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