Statalist The Stata Listserver


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

Re: st: my code for event study


From   "Michael Blasnik" <[email protected]>
To   <[email protected]>
Subject   Re: st: my code for event study
Date   Thu, 15 Mar 2007 07:33:00 -0400

I haven't looked that closely at how the dataset is structured, but I think I'd try Ingo's suggestion first -- the statsby code uses the -in- approach for sample identification and so works pretty quickly. Something like this may do what you want:

keep if est_window==1
statsby , by(id): reg ret mkt
sort id
save mycoeffs
use mydata
sort id
merge id using mycoeffs
gen pred_rtn=_b_cons+_b_mkt*mkt if event_window==1

Some other suggestions that will speed up the code you show include making sure to drop all observations that aren't needed -drop if est_window!=1 & event_window!=1, and even breaking up the dataset into smaller pieces and run the loop on each chunks and re-assemble the results.

Michael Blasnik

----- Original Message ----- From: "Ingo Brooks" <[email protected]>
To: <[email protected]>
Sent: Thursday, March 15, 2007 4:03 AM
Subject: Re: st: my code for event study



Nian,

Did you also try to use -statsby- , then merge the coefficient
estimates to your existing dataset and compute the predicted values by
yourself? I think this should be much faster and easier to implement
than the "in" solution.

Best,
Ingo

On 3/15/07, Nian Huang <[email protected]> wrote:
I want to thank everybody for their previous quick responses.

Here is my piece of code for event study. Basically, I get it from the
Stata sample program.


forvalues i=1(1)1314 {
        quietly reg ret mkt if id==`i' & est_window==1
        quietly predict p if id==`i'
        quietly replace pred_rtn= p if id==`i' & event_window==1
        quietly drop p
}

The above program took 30 minutes to run through. Is there any way to
improve it?
*
*   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