How to generate different series in the same regression?

For questions regarding the import, export and manipulation of data in EViews, including graphing and basic statistics.

Moderators: EViews Gareth, EViews Jason, EViews Steve, EViews Moderator

fsaunders
Posts: 10
Joined: Mon May 15, 2023 4:37 am

How to generate different series in the same regression?

Postby fsaunders » Fri Aug 04, 2023 2:54 am

Hello!

I want to generate three regressions, for each x_{%variables}, but the result of d1, d2, and d3 is modified and they generate the same result in the three new series. My commands are the following:

smpl 2018q1 @last
%SERIES = "serie1 serie2 serie3"
for %variables {%series}
for !i=1 to 3
genr d{!i}=(x_{%variables}-sdlogy)^2
next
next


My results are the same for d1, d2 and d3. For example:
results d1:
Modified: 2018Q1 2023Q1 // d1=(x_serie1-sdlogy)^2
Modified: 2018Q1 2023Q1 // d1=(x_serie2-sdlogy)^2
Modified: 2018Q1 2023Q1 // d1=(x_serie3-sdlogy)^2


And what I want is to have three series, like this:
d1=(x_serie1-sdlogy)^2
d2=(x_serie2-sdlogy)^2
d3=(x_serie3-sdlogy)^2


I would appreciate any comments. Thanks in advance.

EViews Matt
EViews Developer
Posts: 564
Joined: Thu Apr 25, 2013 7:48 pm

Re: How to generate different series in the same regression?

Postby EViews Matt » Fri Aug 04, 2023 9:50 am

Hello,

The result you're seeing is due to your use of nested loops. For each of the series named in the outer loop, i.e. "serie1", "serie2", and "serie3", you create three series in the inner loop, i.e. "d1", "d2", and "d3". Each of these series ends up being defined multiple times, as you see the modification comments, and thus holds the data corresponding to the last iteration of the outer loop when %variables = "serie3". I suspect what you actually want is a single loop structure similar to the following:

Code: Select all

smpl 2018q1 @last
for !i=1 to 3
genr d{!i}=(x_serie{!i}-sdlogy)^2
next

The above exploits the fact that the variable names are nicely paired, e.g. "d1" with "serie1", "d2" with "serie2", etc. More arbitrary pairings could be handled in the single loop of a slightly different form:

Code: Select all

smpl 2018q1 @last
for %i %variable 1 serie1 2 serie2 3 serie3
genr d{%i}=(x_{%variable}-sdlogy)^2
next

fsaunders
Posts: 10
Joined: Mon May 15, 2023 4:37 am

Re: How to generate different series in the same regression?

Postby fsaunders » Sat Aug 05, 2023 2:34 am

Hello, thanks so much for your help.The code works very well!


Return to “Data Manipulation”

Who is online

Users browsing this forum: No registered users and 18 guests