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]

From |
"Martin Weiss" <martin.weiss1@gmx.de> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
st: RE: Calculate variances of subsamples |

Date |
Wed, 2 Jun 2010 20:26:52 +0200 |

<> You could of course issue the -rolling- call with -clear- present, -save- the result to a new file and reload your "3105.dta" to start anew for the next stock. The datasets thus -saved- could be -append-ed to form one big dataset afterwards. -postfile- is also an option, as always. BTW, you may be better of with the lag operator "L." for your return calculations. HTH Martin -----Original Message----- From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Lars Knuth Sent: Mittwoch, 2. Juni 2010 20:22 To: statalist Subject: st: Calculate variances of subsamples Dear listers, I have to say thanks to Martin, the recommendation of rolling was great. Unfortunately, I have now a few problems with the implementation. 1. -rolling- works with the "clear" option, but without it does not ("rolling r(Var), window(60) clear: summarize exret" works) 2. I need the data to calculate and store the variances for more than 1000 stock price returns in the end, so can I somehow keep all the data and then perform -rolling- in a loop? 3. Is there also an opportunity to perform the return calculation in a loop? I am attaching parts of the code I have so far. Any ideas would be of great help to me. Thanks in advance! clear* use "C:\...\3105.dta", clear gen int time=_n * Return calculation gen double exret=ex[_n]/ex[_n-1]-1 if _n>1 gen double msciret=msci[_n]/msci[_n-1]-1 if _n>1 gen double msftret=msft[_n]/msft[_n-1]-1 if _n>1 gen double appret=app[_n]/app[_n-1]-1 if _n>1 gen double geret=ge[_n]/ge[_n-1]-1 if _n>1 gen double pgret=pg[_n]/pg[_n-1]-1 if _n>1 gen double jnjret=jnj[_n]/jnj[_n-1]-1 if _n>1 gen double bpret=bp[_n]/bp[_n-1]-1 if _n>1 tsset time * Rolling rolling r(Var), window(60): summarize exret rolling r(Var), window(60): summarize msciret rolling r(Var), window(60): summarize msftret * * 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/

**Follow-Ups**:**st: RE: RE: Calculate variances of subsamples***From:*"Martin Weiss" <martin.weiss1@gmx.de>

**References**:**st: Calculate variances of subsamples***From:*Lars Knuth <knuth.lars@googlemail.com>

- Prev by Date:
**st: Calculate variances of subsamples** - Next by Date:
**Re: st: Binary Variables** - Previous by thread:
**st: Calculate variances of subsamples** - Next by thread:
**st: RE: RE: Calculate variances of subsamples** - Index(es):