Yesterday you wanted the variance in
a window of 5 even if there were only 3 values;
today things are more reasonable!
As many people have found, it is quite
easy to modify a Stata program (although
also quite easy to break it).
You should copy the file in your OS
to say -mymvsumm.ado-.
Then you open it in a text editor.
-doedit- will do fine.
In the first line
program def mvsumm, rclass
you should change "mvsumm" to "mymvsumm"
Below that, insert a new line like
*! mymvsumm 1.0.0 Jan Soko 11 August 2004
Now search the file for the two occurrences
of
if `na' == `window'
and delete them.
Now save the file and try it out. Warning:
not tested!
To keep track of how many actually are in
each window, you could
gen mimyvar = !mi(myvar)
mymvsumm mimyvar , stat(sum) gen(npresent)
I suspect that there is at least one further
change you will want to make, but that,
as they say in the texts, is left as an exercise.
Nick
[email protected]
[email protected]
> Dear Kit and Nick,
>
> thanks you for your prompt responses. I understand your
> concern. However, I am
> applying -mvsumm- in a finance setting: I need to estimate
> the volatility of
> stock returns using the preceding 60 months of returns.
> Sometimes, I have just
> 1 observation missing... and as long as this observation is
> part of the
> preceding 60 months, I get no estimate of the volatility for
> that company's
> stock (i.e. I lose 60 observations by insisting on a complete
> history). I am
> willing to make the tradeoff between gaining 60 observations
> at the cost of a
> slightly less reliable measure of volatility.
>
> In your answer you suggested to clone and reprogram your
> original -mvsumm-. I am
> not a programming whiz - do you have any pointers?
>
> This is a common procedure in finance - I think you may
> underestimate the demand
> for such a feature in -mvsumm- ;-)
>
> Thanks a lot!! Jan
>
>
>
> > Dear Stata users,
>
> > I have a similar question to Adrian's about -mvsumm-.
> Unfortunately, the
> > proposed solution (using -tssmooth-) doesn't work as I am
> interested in
> > moving
> > variances, not moving averages.
>
> > How can I get create a variable that contains the variance
> of the five
> > preceding
> > observations in a panel data set, even if one or two of the
> those preceding
> > observations are missing? And how can I specify the
> minimum number of
> > non-missing observations within the window?
>
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/