Hi, I am trying to run a rolling 3SLS regression in stata and need to find the coefficient and SE of a linear combination
My regular 3SLS regression looks like this:
reg3 (eq1: Q1 P1 Shock Year_21 Year_22) (eq2: Q2 P3 Shock Year_21 Year_22), endog( P1 P3) exog( Lagged_Shock Lagged_Shock)
And I need this:
nlcom (_b[ P1]+ _b[P2])/2
The program to write the rolling regression is
program drop _all
program roll, rclass
version 9.2
syntax varlist(ts) [if]
reg3 `varlist' = `instruments' if `if', endog(`endog') exog(`exog')
nlcom (_b[P1] + _b[P2]) / 2
mat coefs= r(b)
return scalar lcoefs = coefs[1,1]
mat vars = r(V)
return scalar lvars = vars[1,1]
end
rolling, window(20) saving(rslt, replace): roll Q1 Q2 P1 P2 Shock Shock Year_21 Year_22 Lagged_Shock Lagged_Shock, endog(P1 P2) exog(Shock Shock Year_21 Year_22) instruments(Lagged_Shock Lagged_Shock)
However,
it gives the error:
options not allowed
an error occurred when rolling executed roll
Can anyone help?
My regular 3SLS regression looks like this:
reg3 (eq1: Q1 P1 Shock Year_21 Year_22) (eq2: Q2 P3 Shock Year_21 Year_22), endog( P1 P3) exog( Lagged_Shock Lagged_Shock)
And I need this:
nlcom (_b[ P1]+ _b[P2])/2
The program to write the rolling regression is
program drop _all
program roll, rclass
version 9.2
syntax varlist(ts) [if]
reg3 `varlist' = `instruments' if `if', endog(`endog') exog(`exog')
nlcom (_b[P1] + _b[P2]) / 2
mat coefs= r(b)
return scalar lcoefs = coefs[1,1]
mat vars = r(V)
return scalar lvars = vars[1,1]
end
rolling, window(20) saving(rslt, replace): roll Q1 Q2 P1 P2 Shock Shock Year_21 Year_22 Lagged_Shock Lagged_Shock, endog(P1 P2) exog(Shock Shock Year_21 Year_22) instruments(Lagged_Shock Lagged_Shock)
However,
it gives the error:
options not allowed
an error occurred when rolling executed roll
Can anyone help?