Bookmark and Share

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


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

RE: st: RE: combination of rolling and if


From   Nick Cox <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   RE: st: RE: combination of rolling and if
Date   Tue, 13 Dec 2011 22:08:41 +0000

So, you don't like or don't believe my advice but you want some more! 

Please do try reading the help and do _some experimenting yourself_. 

For example, the help for -tssmooth- says 

"Setup
        . webuse sales1
        . tsset

Create uniformly weighted moving average of sales by using two lagged terms, using three
forward terms, and including the current observation in the filter
        . tssmooth ma sm1=sales, window(2 1 3)" 

So, your problem sounds like -window(0 0 12)- after the equivalent set-up. Or perhaps 0 1 11. Does the next 12 months include the current month or not? Only you know for certain. 

In other words, smoothing here emphatically does include moving averages, contrary to your assertion. 

You want to select a group of stocks. You can try this command with or without -if- conditions. That will help you understand what it does. 

It's still my understanding that -rolling- is more complicated than you want. If you work out how to use it and find that I am wrong, I would be interested to hear about that. 

Nick 
[email protected] 

qing ye

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.

On 14 December 2011 05:28, Nick Cox <[email protected]> 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.

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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index