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]

AW: st: mean calculation & exclusion of certain observations


From   "Loew, Philipp" <[email protected]>
To   "[email protected]" <[email protected]>
Subject   AW: st: mean calculation & exclusion of certain observations
Date   Wed, 22 Jan 2014 09:06:56 +0000

Thank you for your hint, Maarten. However I would like to avoid the rolling and tsfill commands, since my dataset is already quite large, that is why I tried to to expand the code provided by Nick Cox in Stata tip 51:

gen mean_price = .
quietly forval i = 1/`= _N' {
summarize price if sector == sector[`i'] & inrange(date, date[`i']-30,date[`i']), meanonly replace mean_price = r(mean) in `i'
}
- as you can see, a rule that retains only most recent price of each company is still missing.


-----Ursprüngliche Nachricht-----
Von: [email protected] [mailto:[email protected]] Im Auftrag von Maarten Buis
Gesendet: Mittwoch, 22. Januar 2014 09:39
An: [email protected]
Betreff: Re: st: mean calculation & exclusion of certain observations

On Tue, Jan 21, 2014 at 11:29 PM, Loew, Philipp wrote:
> I try to calculate a mean stock price by industry sectors and would like to exclude specific observations.
> The mean should include only the most recent price of each company 
> which is part of the sector and the mean should be calculated in a certain range (e.g., 30 days). The observations in the dataset are irregularly spaced.

I suspect you are looking for the -rolling- command. If you first specify -tsset sector date-, -rolling- will work within each sector.


Hope this helps,
Maarten

---------------------------------
Maarten L. Buis
WZB
Reichpietschufer 50
10785 Berlin
Germany

http://www.maartenbuis.nl
---------------------------------
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/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/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


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