Hi, I am trying to create a same base price index for many series that starts with 100 at the most recent year and goes backwards based on the period price change. However for this to work, as it is calculated backwards I need to execute the equation many times until the first observation for each series. How can I write e loop for it that finishes at the first observation of each series ?
smpl @now1 @now1
aapool_reits.genr idxprice?=100
smpl @first @now2
aapool_reits.genr idxprice?=idxprice?(1)/(1+@pch(price?(1)))
Loop to run equation
Moderators: EViews Gareth, EViews Jason, EViews Moderator, EViews Matt

 EViews Developer
 Posts: 336
 Joined: Thu Apr 25, 2013 7:48 pm
Re: Loop to run equation
Hello,
Mathematically, your idxprice is just a scaled version of price. There's no need to explicitly evaluate that equation backwards through your observations, just scale the data so that the target observation has a value of 100. For example,
Mathematically, your idxprice is just a scaled version of price. There's no need to explicitly evaluate that equation backwards through your observations, just scale the data so that the target observation has a value of 100. For example,
Code: Select all
%tmp = @datestr(@now)
aapool_reits.genr idxprice? = price? * 100 / @elem(price?, %tmp)

 Posts: 24
 Joined: Fri Aug 14, 2015 7:54 am
Re: Loop to run equation
Great ! It worked, however I got to change the second line to aapool_reits.genr idxprice? = price? * 100 / @elem(price?, @now), as the %tmp version gives me a message "illegal date %tmp". How can I do If I want to use @now1 or @now4 as it does not work in this script ?
Thanks
Thanks

 EViews Developer
 Posts: 336
 Joined: Thu Apr 25, 2013 7:48 pm
Re: Loop to run equation
Curious. Perhaps the issue is that an expression such as @now1 or @now4 behaves differently as part of a smpl command than it does as part of a general expression. In a smpl command, the 1 or 4 are in units of your workfile's frequency, e.g., years. However, in a general expression the units match the date number returned by @now, i.e., days. In other words, in your smpl commands @now4 means today's date minus four years, but inside @datestr @now4 means today's data minus four days. Use @dateadd to make sure the date is changing in the units you intend. Try,
Code: Select all
%tmp = @datestr(@dateadd(@now, 1, "YY"))
aapool_reits.genr idxprice? = price? * 100 / @elem(price?, %tmp)

 Posts: 24
 Joined: Fri Aug 14, 2015 7:54 am
Re: Loop to run equation
Illegal date too...But that's fine, I can go with @now only. However the issue in my next steps comes when I try to deflate this series to transform it in real prices (discounted by inflation). To do this you have to go backwards, how can I do it ? The math formula is this, however Eviews can't calculate:
aapool_reits.genr idxpricereal?=idxpricereal?(1)/(1+inflation?(1))*(1+@pch(idxprice?(1)))
aapool_reits.genr idxpricereal?=idxpricereal?(1)/(1+inflation?(1))*(1+@pch(idxprice?(1)))

 EViews Developer
 Posts: 336
 Joined: Thu Apr 25, 2013 7:48 pm
Re: Loop to run equation
Very odd.
Anyway, the regular (nonpool) genr command can calculate a series backwards, so a combination of your initial code and a loop over the crossids in the pool should do the trick. For example,
Anyway, the regular (nonpool) genr command can calculate a series backwards, so a combination of your initial code and a loop over the crossids in the pool should do the trick. For example,
Code: Select all
%tmp = aapool_reits.@crossids
for %cid {%tmp}
smpl @now1 @now1
genr(r) idxpricereal{%cid}=100
smpl @first @now2
genr(r) idxpricereal{%cid}=idxpricereal{%cid}(1)/(1+inflation{%cid}(1))*(1+@pch(idxprice{%cid}(1)))
next

 Posts: 24
 Joined: Fri Aug 14, 2015 7:54 am
Re: Loop to run equation
Thanks Matt, however the results are different than the math calc. I made an excel spreadsheet with the result series calculated by Eviews and the correct one calculated by Excel, please see attached. I also adjusted your formula so it matches the previous idxprice script and the inflation (which should be divided by 100).Below the script and attached is the spreadsheet. Thanks for your help.
%tmp = aapool_reits.@crossids
for %cid {%tmp}
smpl @now @now
genr(r) idxpricereal{%cid}=100
smpl @first @now1
genr(r) idxpricereal{%cid}=(idxpricereal{%cid}(1))/((1+@pch(idxprice{%cid}(1)))*(1+inflation{%cid}(1)/100))
next
%tmp = aapool_reits.@crossids
for %cid {%tmp}
smpl @now @now
genr(r) idxpricereal{%cid}=100
smpl @first @now1
genr(r) idxpricereal{%cid}=(idxpricereal{%cid}(1))/((1+@pch(idxprice{%cid}(1)))*(1+inflation{%cid}(1)/100))
next
 Attachments

 Eviews.xlsx
 (10.36 KiB) Downloaded 35 times

 EViews Developer
 Posts: 336
 Joined: Thu Apr 25, 2013 7:48 pm
Re: Loop to run equation
I don't know what calculations you performed in Excel, so I can't say why you're getting different results in EViews. Chances are that either the Excel formula or the EViews formula is not calculating what you think it is.

 Posts: 24
 Joined: Fri Aug 14, 2015 7:54 am
Re: Loop to run equation
Matt,
The equation that I want to calculate and which is shown in the Excel spreadsheet I attached in the last post is: idxpricereal = idxpricereal(1)/((1+(idxprice(1)/idxprice1))*(1+inflation(1)/100)). However the script below does not have show the same results of this former equation.
genr(r) idxpricereal{%cid}=(idxpricereal{%cid}(1))/((1+@pch(idxprice{%cid}(1)))*(1+inflation{%cid}(1)/100))
The equation that I want to calculate and which is shown in the Excel spreadsheet I attached in the last post is: idxpricereal = idxpricereal(1)/((1+(idxprice(1)/idxprice1))*(1+inflation(1)/100)). However the script below does not have show the same results of this former equation.
genr(r) idxpricereal{%cid}=(idxpricereal{%cid}(1))/((1+@pch(idxprice{%cid}(1)))*(1+inflation{%cid}(1)/100))

 EViews Developer
 Posts: 336
 Joined: Thu Apr 25, 2013 7:48 pm
Re: Loop to run equation
The formula in your Excel file is missing the parentheses around the denominator.

 Posts: 24
 Joined: Fri Aug 14, 2015 7:54 am
Re: Loop to run equation
Issue solved !..Thanks Matt, sorry for the parenthesis error
Who is online
Users browsing this forum: No registered users and 7 guests