JanDitzen / xtdcce2

Estimating Dynamic Common Correlated Effects Models in Stata
https://janditzen.github.io/xtdcce2/
28 stars 14 forks source link

Jackknife #1

Closed JanDitzen closed 5 years ago

JanDitzen commented 5 years ago

If option jackknife is used, then the cross sectional averages need to be partial out over the first and the second half of the dataset, rather than over the entire.

See attached code:

clear

set obs 100

gen t = _n

gen x = rnormal() gen cons = 1 gen y = 2cons + 0.5x + rnormal()

reg y cons , noconst predict ytilde , res

reg x cons, noconst predict xtilde, res

reg y x scalar b1mg = _b[x] reg ytilde xtilde, noconst scalar b1mgtilde = _b[xtilde]

** Jackknife

reg y x if t < 50 scalar b1 = _b[x]

reg y x if t >= 50 scalar b2 = _b[x]

reg ytilde xtilde if t < 50, noconst scalar b1tilde = _b[xtilde]

reg ytilde xtilde if t >= 50, noconst scalar b2tilde = _b[xtilde]

** Correct partial out reg y cons if t < 50, noconst predict y1tilde, res reg y cons if t >= 50, noconst predict y2tilde, res

reg x cons if t < 50, noconst predict x1tilde, res reg x cons if t >= 50, noconst predict x2tilde, res

reg y1tilde x1tilde if t < 50, noconst scalar b12tilde = _b[x1tilde] reg y2tilde x2tilde if t >= 50, noconst scalar b22tilde = _b[x2tilde]

display "normal regression" display 2b1mg - 0.5 (b1 + b2 ) display "wrong model" display 2b1mgtilde - 0.5 (b1tilde + b2tilde) display "correct model with partial out for each half" display 2b1mgtilde - 0.5 (b12tilde + b22tilde)

JanDitzen commented 5 years ago

Correct Method for test: xtdcce2135 y L.y, cr(y) cr_lags(2) matrix MG = _b[L.y] matrix MGi = e(bi) sum t scalar Tmax = r(max) local Tboundary = Tmax / 2 xtdcce2135 y L.y if t < Tboundary' , cr(y) cr_lags(2) matrix MG1 = _b[L.y] matrix MG1i = e(bi) xtdcce2135 y L.y if t >=Tboundary' , cr(y) cr_lags(2) matrix MG2 = _b[L.y] matrix MG2i = e(bi)

Coefficients mata 2st_matrix("MG") :- 0.5: (st_matrix("MG1") :+ st_matrix("MG2")) Standard Errors mata sqrt(variance(2:st_matrix("MGi")':-0.5: (st_matrix("MG1i")' :+ st_matrix("MG2i")')))

JanDitzen commented 5 years ago

Solved for IV and MG regressions. Added Column 13 to mata variable container. For mg_regression, variablenames are swapped in regression mata program. For IV, jackknife partialled out are seperated out, names swapped. Important: order needs to remain the same.