# st: Proportions

 From "Yvonne Capstick" <[email protected]> To [email protected] Subject st: Proportions Date Mon, 24 Jan 2005 22:51:01 -0500

Hi,

I have a hopefully simple question on calculating proportions.

I have daily returns (ret) for different stocks (stock) and I would like to calculate the proportion of days for which a firm's daily stock return was below 5% over the last 3 calendar years.

If all I needed was the proportion of trading days for which the return was below 5% over the last 1 calendar year, I could calculate this by the following long-winded method:

gen lo = 0
replace lo = 1 if ret < -5
egen temp = count(lo), by (stock year)
egen temp2 = sum(lo), by (stock year)
gen prop = temp2/temp
gen temp3 = prop[_n-1] if month == 1 & month[_n-1] == 12 & year == year[_n-1]+1
egen lastprop = sum(temp3), by (stock year)

a) There must be a faster way of doing the above - I tried something like egen prop = count(lo)/sum(lo), by (stock year) but it said 'varlist not allowed". Please could you advise me of any faster way?
b) How do I modify the above to calculate the proportion of trading days where the return was < 5% over the last 3 calendar years?

Thanks very much in advance for any assistance.
Yvonne

_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today - it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/

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