'''program sim_fmols05   (omits my own fmols calculations)

'''Compares lrcov as calculated by command LRCOV to the lrcov calculated by regression equation command COINTREG 
''''''I have been unable to get equivalent results by playing with the command options

''' "omega" = lrcov as calculated by command LRCOV
'''  "e_omega" = lrcov as calcuated by regression command COINTREG
'''Also compares one-sided lrcov 
''' "p_lambda" = second two columns of one-sided lrcov as calculated by command LRCOV
''' "e_lambda" = one-sided lrcov as calculated by regression command COINTREG

'''Begins by generating simulated x-process vars x1 x2 and ar(1) error process rr
'''Then generates simulated y as cointegrated with x1 x2 and a constant, errors ar(1)

'''Uses ls to generate cointegration residuals  u1
''' x-process residuals are equal to first differences



WFcreate q 1959.1  2010.4
smpl 1959.1 1959.1
genr x1 = 10
genr x2 = 2
smpl 1959.2 2010.4
genr x1 = x1(-1) +nrnd
genr x2  = x2(-1) +nrnd

genr cx1 = x1 -x1(-1)
genr cx2 = x2 -x2(-1)
smpl 1959.1 1959.1
genr rr = 2*nrnd
smpl 1959.2 2010.4
genr rr = 0.8*rr(-1) +0.7*nrnd
smpl 1959.1 2010.4
genr y = 5 +0.3*x1 -0.3*x2 +rr  '''autocorrelated errors in cointegration process 


smpl 1959.1 2010.4    
ls y c x1 x2

smpl 1959.2 2010.4
genr u1 = resid    ''''first stage cointegrating residuals

genr u_x1 =cx1   ''''differenced x-process residuals, no constant
genr u_x2 = cx2
group gu  u1  u_x1  u_x2    '''group the cointegrating model and x-var residuals


gu.lrcov(window=sym,noc,lag=1,kern=bart,bw=fixednw,noc,out=omega)   '''estimate long-run covariance, results placed in omega
gu.lrcov(window=lower,noc,lag=1,kern=bart,bw=fixednw,noc,out=lambda)   '''estimate one-sided (lag) covariance, results placed in lambda.

equation e_eviews.cointreg(method=fmols, trend=const, regdiff, regtrend=none, lag=1, kern=bart, bw=fixednw) y x1 x2
'''As far as I can tell, these options are equiv to the options in the lrcov command above.

matrix e_omega = e_eviews.@lrcov    '''''eviews cointreg proc est of lrcov
matrix e_lambda = e_eviews.@lambda12cov   ''''eviews cointreg proc est of one-sided
matrix p_lambda = @subextract(lambda,1,2,3,3)    '''omits first column of one-sided lrcov as generated by LRCOV command

matrix dif_omega = e_omega -omega             '''''Difference between calc by LRCOV and calc by COINTREG
matrix dif_lambda = e_lambda -p_lambda
