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

st: RE: Calculating Empirical CDFs


From   "Scott Merryman" <[email protected]>
To   <[email protected]>
Subject   st: RE: Calculating Empirical CDFs
Date   Tue, 28 Dec 2004 21:07:48 -0600

> -----Original Message-----
> From: [email protected] [mailto:owner-
> [email protected]] On Behalf Of Yvonne Capstick
> Sent: Tuesday, December 28, 2004 12:36 PM
> To: [email protected]
> Subject: st: Calculating Empirical CDFs
> 
> Hi,
> 
> I've using Stata to do some returns analysis, and have converted daily
> returns into standardized normal variables, nret. I now would like to
> calculate the fraction, F(z) of nret that are less than -3, -2, -1, 0, 1,
> 2,
> 3 and then calculate the standard deviation of F(z), using the formula
> stdev(F(z)) = (F(z))(1-F(z))/n)^0.5.
> 
> I can generate the number of observations less than each cut-off using:
> 
> forvalues z=-3/3 {
> count if nret < `z'
> }
> 

Take a look at [P] return, [R] saved results, or -whelp return-.

One way, following the structure you have, would be:

gen count = .
local j = 1
forv i = 1/5 {
	qui {
	count if nret <  `i'
	replace count = r(N) in `j'
	local j = `j' + 1
}
}


> 
> 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). 




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