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]
st: mean calculation & exclusion of certain observations
From
"Loew, Philipp" <[email protected]>
To
"[email protected]" <[email protected]>
Subject
st: mean calculation & exclusion of certain observations
Date
Tue, 21 Jan 2014 22:29:48 +0000
Dear all,
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 tried to expande 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.
Hopefully someone can help me out.
Kind Regards
Philipp
*
* 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/