Page 1 of 1
Models and groups
Posted: Wed Mar 22, 2023 1:56 am
by F_Alberto
Dear all,
I am trying to build a model with some variables.
Then, inside the model, I would like to create the maximum of the lags of one of the variables. However, @rmax only works with groups and in the model objects groups are not allowed. I am stuck right now. Could you help me?
Thanks
Re: Models and groups
Posted: Wed Mar 22, 2023 8:29 am
by EViews Gareth
Could you go in to more detail? I don't understand what you're trying to do.
Re: Models and groups
Posted: Thu Mar 23, 2023 1:01 am
by F_Alberto
Hi Gareth. I'll try.
I would to like to replicate a variable akin to the net of Hamilton. That is, if x is my variable, the code for Eviews would be something similar to:
group mygroup x(-1) x(-2)...
series net = @recode(x-@rmax(mygroup)>0,x-@rmax(mygroup),0)
I do not have a problem with this (I have done correctly in my program). However, it is different when I build a model.
If I have a model with some equation and I would like to forecast y, and it depends of net, I also need a forecast of net, that should be done in the object model with solve. However, "model" does not accept groups, so I cannot create "mygroup" inside or append it.
Also, I cannot write something similar to:
series net = @recode(x-@rmax( x(-1) x(-2)....)
Because @rmax only works with groups.
I hope this helps.
Thank you!
Re: Models and groups
Posted: Thu Mar 23, 2023 9:56 am
by EViews Matt
Hello,
You can use nested calls to @pmax as a replacement for @rmax. For example,
Code: Select all
net = x - @pmax(x(-1), @pmax(x(-2), @pmax(x(-3), ...)))
Re: Models and groups
Posted: Fri Mar 24, 2023 12:25 am
by F_Alberto
Thank you!
Re: Models and groups
Posted: Fri Mar 24, 2023 2:12 am
by F_Alberto
One additional (and I hope last) problem.
I have created a code but it runs very, very slow. I have been trying to understand why, but I have been unable to. Could you help me?
This is the loop part, which is the part in which the program is very low. In case that is necessary I can provide more.
scalar nboot = 1000
scalar nhist = 50
scalar ndraws = 100
scalar h = 8
scalar p = 6
for !boot=0 to nboot
if !boot>0 then
'Initial conditions
smpl {primera} {ultima}
xraw.resample(block=p,dropna,suffix=xrawres)
yraw.resample(block=p,dropna,suffix=yrawres)
'
smpl {dstartsample} {dstartsample}+p-1
genr x = xrawres
genr y = yrawres
series xplus = @recode(x>0, x, 0)
smpl {bstartsample} {bendsample}
uxbase.resample(dropna,suffix=uxres)
uybase.resample(dropna,suffix=uyres)
genr xpath = uxres
genr ypath = uyres
'Solve the model with the boot
bootasymm.scenario(n,a="_b") "scenario boot"
bootasymm.addassign(c) @stochastic
y_a = ypath
x_a = xpath
bootasymm.solve
bootasymm.scenario(d) "scenario boot"
''''
genr x = x_b
genr y = y_b
genr xplus = xplus_b
endif
''''Estimating the model: boostrapped data.
'''''X regression
'Estimations
equation xeq.ls x c y(-1 to -{p}) x(-1 to -{p})
'Residuals
genr ux = resid
'X std
scalar sigmax = @stdev(ux)
'''Y regression
equation yeq.ls y c y(-1 to -{p}) x(0 to -{p}) xplus(0 to -{p})
'Residuals
genr uy = resid
'''''Model define
model asymvar xeq yeq
asymvar.append xplus = @recode(x>0 , x , 0)
asymvar.append @identity ly = ly(-1) + y
'''Save the bootstrapped data
smpl {dstartsample} {dendsample}
genr xboot = x
genr yboot = y
for !hist = 1 to nhist
'Resample for initial conditions
smpl {dstartsample} {dendsample}
xboot.resample(block=p,dropna,suffix=xbootres)
yboot.resample(block=p,dropna,suffix=ybootres)
smpl {ultima}+1-p {ultima}
genr x = xbootres
genr y = ybootres
series xplus = @recode(x>0,x,0)
''''''
for !draw=1 to ndraws
'Resample residuals
smpl {bstartsample} {bendsample}
ux.resample(dropna,suffix=uxres)
uy.resample(dropna,suffix=uyres)
smpl {hstartssample} {hendsample}
genr xpath = 0
genr ypath = 0
for !j=1 to h
xpath(bend+!j) = uxres(bend-!j)
ypath(bend+!j) = uyres(bend-!j)
next
'This is the base
asymvar.scenario(n, a="_2") "scenario 2"
asymvar.addassign(c) @stochastic
y_a = ypath
x_a =xpath
asymvar.solve
''''
for !i = 1 to 2
scalar delta = !i*sigmax
'Resolve the model for +delta
asymvar.scenario(n, a="_3") "scenario 3"
xpath(bend+1) = delta
x_a =xpath
asymvar.solve
'Resolve the model for minus delta
asymvar.scenario(n, a="_4") "scenario 4"
xpath(bend+1) = -delta
x_a =xpath
asymvar.solve
'Sum of the plus and minus responses.
vector vly_2 = @convert(ly_2)
vector vly_3 = @convert(ly_3)
vector vly_4 = @convert(ly_4)
for !j=1 to h
gap(!j) = vly_4(!j)+vly_3(!j)-2*vly_2(!j)
next
'
if !boot>0 then
testboot_!i = testboot_!i+gap
else
test_!i = test_!i + gap
endif
asymvar.scenario(d) "scenario 3"
asymvar.scenario(d) "scenario 4"
next
asymvar.scenario(d) "scenario 2"
next
next
if !boot>0 then
for !i=1 to 2
testboot_!i = testboot_!i/(nhist*ndraws)
sumirf_!i = sumirf_!i + testboot_!i
matrix testboottrans_!i = @transpose(testboot_!i)
sumirfsq_!i = sumirfsq_!i + testboot_!I*testboottrans_!i
next
endif
next
Re: Models and groups
Posted: Mon Mar 27, 2023 1:37 pm
by EViews Matt
Hello,
I don't see anything in your code that would specifically impair performance, there's simply a large number of iterations to be executed. In case you weren't already doing so, running the program in quiet mode may yield a modest performance improvement. Programs that execute a lot of individually simple code lines, as your program does, generally benefit the most from quiet mode since the overhead of updating EViews' GUI is removed.