Hello!
I hope you are in good health.I would like to simulate 500 maximum likelihood estimators of an autoregressif 2 coefficients. But i don't know how to store the estimators from the following algorith:
@monte carlo maximum de vraisemblance exacte
rndseed 1 'set seed for random number generator
!mm= 500 'number of experiments
!nn = 1000 'total length of workfile
'create workfile
create u !nn
'create a vector
@vector(!mm) estm_1
@vector(!mm) estm_2
!phi1 = 0.4 'AR 1 term
!phi2 = -0.2 'AR 2 term
!k=2 'number ar terms
'create workfile
create u !nn
'declare objects to be used in simulations
matrix(!mm,!k) Cmat 'matrix to store coefficient values over simulations
'run simulations
for !sim=1 to !mm
@declaration
rndseed 123
series y=0
smpl @first+2 @last
genr y=!phi1*y(-1)+!phi2*y(-2) +nrnd
@creation dune variable pour t=1
series d1=0
smpl @first @first
d1=1
smpl @all
@creation dune variable pour t=2
series d2=0
smpl @first+1 @first+1
d2=1
smpl @all
@condition initiale
equation eq1.ls y ar(1) ar(2)
coef(1) phi1=c(1)
coef(2) phi2=c(2)
coef(3) s2=eq1.@se^2
@ la fonction log vraisemblance
logl ar2
ar2.append @logl logl2
ar2.append var=@recode(d1=1 or d2=1,s2(1)/(1-phi1(1)^2-phi2(1)^2),s2(1))
ar2.append res=@recode(d1=1 or d2=1,y,y-phi1(1)*y(-1)-phi2(1)*y(-2))
ar2.append sres=res/@sqrt(var)
ar2.append logl2=log(@dnorm(sres))-log(var)/2
@lancer maximum de vraisemblance
ar2.ml(showopts,m=1000,c=1e-5)
show ar2.output
'store coefficients estimates
@estm_1(!sim) = ar2.@coef(1)
@ estm_2(!sim) = ar2.@coef(2)
rowplace(Cmat,@transpose(ar2.ml @coefs),!sim)
next
'reset sample
smpl @all
vector cres=@cmean(cmat)
show cres
@mtos(estm_1,seri1)
@mtos(estm_2,seri2)
monte carlo :maximum likelihood estimator
Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13604
- Joined: Tue Sep 16, 2008 5:38 pm
Re: monte carlo :maximum likelihood estimator
You appear to have lines that start with an @ symbol. That isn't valid syntax in EViews.
Who is online
Users browsing this forum: No registered users and 2 guests
