Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
st: making code faster
From
Rudy Hover <[email protected]>
To
[email protected]
Subject
st: making code faster
Date
Mon, 14 May 2012 16:09:19 +0200
> I have a lot of regressions to run (on stock returns of firms over a
> periof of 7 years) in order to retrieve the residuals.
>
> I am using the code
>
>
> gen touse = !missing(excessreturn, marketreturn, firmno, year)
>
> bysort touse firmno year : replace touse = 0 if _N == 1
>
> egen group = group(firmno year) if touse
>
> su group
>
> local max = r(max)
>
> gen residuals = .
>
> qui forval i = 1/`max' {
>
> reg excessreturn marketreturn if group == `i'
>
> predict temp, residuals
>
> replace residuals=temp if group == `i'
>
> drop temp
>
> }
>
>
>
> How could I make it any faster using -in- instead of -if- ?
>
> It takes hours now.
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/