Dear Statalist,
I have a code (loop) to run time series regressions for each company (Identifier: lpermno) of prices (prccq) on earnings per share (epspiq). The code looks like this:
It gives back the alpha, beta and their standard errors from the regressions in new columns of my original data.
Unfortunately my code is way too slow. To run through once it takes 1.5 to 2 hours (I have almost 700,000 observations).
Is it possible to speed this up in mata? I’ve been trying to adapt a rangestat code to my needs (I used this one from Robert Picard as a starting point: https://www.statalist.org/forums/for...tas-for-stocks) but unfortunately was unsuccessful.
Any advice is appreciated.
Thanks in advance,
Timo
I have a code (loop) to run time series regressions for each company (Identifier: lpermno) of prices (prccq) on earnings per share (epspiq). The code looks like this:
Code:
gen alpha =. gen alpha_stderr =. gen beta =. gen beta_stderr =. levelsof lpermno, local(levels) foreach i of local levels { reg prccq epspiq if lpermno== `i',robust replace alpha = _b[_cons] if lpermno == `i' replace alpha_stderr = _se[_cons] if lpermno == `i' replace beta = _b[epspiq] if lpermno == `i' replace beta_stderr = _se[epspiq] if lpermno == `i' } gen alpha_tstat = alpha / alpha_stderr gen beta_tstat = beta / beta_stderr save alphas_per_lpermno, replace
Unfortunately my code is way too slow. To run through once it takes 1.5 to 2 hours (I have almost 700,000 observations).
Is it possible to speed this up in mata? I’ve been trying to adapt a rangestat code to my needs (I used this one from Robert Picard as a starting point: https://www.statalist.org/forums/for...tas-for-stocks) but unfortunately was unsuccessful.
Any advice is appreciated.
Thanks in advance,
Timo
Comment