Statalist The Stata Listserver

[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Took forever to run an event study program

From   "Austin Nichols" <>
Subject   Re: st: Took forever to run an event study program
Date   Wed, 14 Mar 2007 14:42:48 -0500

I cannot see how it would take 30min unless you have an absurdly out
of date computer, grossly insufficient memory, or have coded the
procedure (to save the relevant post-regression output) very
inefficiently.  Here is a fake example that takes ~30sec to load 130
datasets (one event per dataset, with several hundred years of daily
data) and compute and save 3 residuals in each, so it would take about
5min for 1300 datasets.  However, if all the events are in one file
(so you don't have to load separate data files), it should run
considerably faster. If you only have to run one regression, and
compute residuals once, it should take about a second. Without seeing
your code, we cannot comment on the source of the inefficiency.

set seed 12345
set obs 100000
gen t=_n
postutil clear
tempfile temp
postfile v id e1 e2 e3 using `temp'
set rmsg on
qui {
gen car=sum(uniform()+.01)
forv id=1/130 {
 tempfile t`id'
 gen event=uniform()>.9999
 replace event=0 if sum(event)>1
 su t if event==1, meanonly
 gen et=t-r(mean)
 save `t`id''
 drop event et
drop _all
qui {
forv id=1/130 {
 use `t`id''
 qui reg car et if inrange(et,-230,10)
 predict resid if e(sample), resid
 forv i=1/3 {
  su resid if et==`i'-2, meanonly
  local e`i'=r(mean)
 post v (`id') (`e1') (`e2') (`e3')
 drop _all
postclose v

On 3/14/07, Nian Huang <> wrote:
I have around 1,300 events. For each event, I need to calculate CAR
(cumulative abnormal return) around the event based on the market
model. The event window is 3 days (-1,  1). The CAR is totalled for
the 3 days period. The estimation window is 241 days (-250, -10)  In
Stata, for each event, a simple linear regression will be estimated
around the estimation window. Then based on the fitted line, residuals
will be calculated for the 3-day event window. Since I have around
1,300 events, Stata will do the same routine around 1,300 times.
I ran the program several times, and everytime it would take more than
30 minutes to finish the task.  I asked some of my
colleagues--unfortunately, they use SAS instead of Stata, and they
said for the task, it only takes around several seconds in SAS.
*   For searches and help try:

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