Dear Statalist,

I might be shooting my shot with this post but I want to implement the eivreg command in a rolling-windows setting using an unbalanced panel (id x tid).
Currently, I am able to run the program but the estimates are not stored correctly. I would like to save the regression coefficients in a _b_* variables and the t-stats in _t_* variables.

The specifications for the rolling windows are the last 36 months (minimum 12 months of observations) by id. r_rf, mkt, and smb are assumed to be random variables.
The matrix r(table) stores the estimates for each window.

From similar threads (with other regressors), I ended up with this code.

Code:
g _b_mkt=.
g _b_smb=.
g _t_mkt=.
g _t_smb=.

capture program drop eiv_rol
program define eiv_rol

    qui: eivreg  r_rf mkt  smb ,  r(mkt 0.6 smb 0.6) 
    matrix mattest= r(table)
    
    replace _b_mkt= mattest[1, 1] if mi(_b_mkt)
    replace _b_hml= mattest[1, 2] if mi(_b_smb)
    replace _t_mkt= mattest[3, 1] if mi(_t_mkt)
    replace _t_hml= mattest[3, 2] if mi(_t_smb)
    
    exit
end

rangerun eiv_rol, by(id) interval(tid -36 -1)
If the estimates can be stored properly, I want to re-run the program changing the reliability (in this example case the reliability for both variables is 0.6). I am planning to increment by .1 in each step from 0 to 1. What other procedure would you recommend to speed up the process?

Another problem that I am facing is that I cannot break the code in between. I need to wait until the end to made changes, which might take several minutes. Do you know how to change this behavior?
Thank you

Ricardo