Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: re calculating empirical cdfs


From   Christopher F Baum <[email protected]>
To   [email protected]
Subject   st: re calculating empirical cdfs
Date   Wed, 29 Dec 2004 11:10:34 -0500

Yvonne said

Separately, I would like to calculate the standard deviation of returns for
a particular year, e.g. egen stdev = stdev(nret), by(year), but there
doesn’t seem to be a stdev function (or any variants). The “summarize”
function gives me standard deviations but doesn’t store these as a variable.
I’ve been able to calculate the standard deviation manually, by squaring
the normalized returns and dividing them by the total number of observations
less one, but thought that Stata must have a function to do this.

help egen turns up sd()...and from that help file,

count(exp) (allows by varlist)
creates a constant (within varlist) containing the number of nonmissing
observations of exp. Also see robs() and rmiss() below.

so I don't understand " I’m using Stata 8, which doesn’t seem to allow
me to do a egen temp = count(x) like previous Stata version".

Not clear that any egens are needed, though. If you want the results stored in variables:

clear
local nn 10000
set obs `nn'
g ret = invnorm(uniform())
g sigma = .
g res = .
g sd = .
local j 0
qui forv i= -3/3 {
count if ret < `i'
local ++j
replace sigma = `i' in `j'
replace res = r(N)/`nn' in `j'
replace sd = sqrt(res[`j']*(1-res[`j'])/`nn') in `j'
}
l sigma res sd in 1/7

Kit Baum, Boston College Economics [email protected]
http://ideas.repec.org/e/pba1.html


*
* 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/




© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index