Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • eivreg in rolling window setting (estimates not stored properly)

    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









  • #2
    I think I got it. The values should be generated inside the program instead of replacing them. Here is an example with data.

    Code:
    webuse grunfeld, clear
    
    xtset company  year
    capture program drop eiv_rol
    program define eiv_rol
            xtset id tid
            qui: eivreg   invest mvalue kstock ,  r(mvalue 0.95 kstock 0.95)  
            matrix mattest= r(table)    
            foreach v in  mvalue kstock  {
            gen b_`v' = _b[`v']
            gen t_`v' = _b[`v']/_se[`v']
            }
    exit
    end
    
    rangerun eiv_rol, by(company) interval (year -6 -1) verbose

    Comment

    Working...
    X