'''program sim_fmols04   (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 from regressing change in x on a constant, I think this is imposed by use of COINTREG command below.  But calculating x-process residuals as equal to the change in x does not fix the lack of equiv results



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 (else fmols has nothing to do)


smpl 1959.1 2010.4    '''Question: To be consisetent with eviews command COINTREG, should this estimation omit first observation??????
ls y c x1 x2

smpl 1959.2 2010.4
genr u1 = resid

ls cx1 c
genr u_yh = resid    ''''to be consistent with use of cointreg command below.
'''genr u_yh =cx1
ls cx2 c
genr u_r = resid
'''genr u_r = cx2
group gu  u1  u_yh  u_r    '''group the cointegrating model and x-var residuals


gu.lrcov(window=sym,lag=1,kern=bart,bw=fixednw,noc,out=omega)   '''estimate long-run covariance, results placed in omega
gu.lrcov(window=lower,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, 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
