Hi,
I have a data panel dim (4,3).
This is the code I use to subtract obsid=2- obsid=3 in crossid=4 for January:
smpl @all if @crossid=4 and @obsid=2
series result=@maxsby(JAN,@crossid=4, @obsid=2) - @maxsby(JAN,@crossid=4,"if @crossid=4 and @obsid=3")
I would like to perform the same subtraction for all @crossid with a loop.
This is the code I am working on:
for !i=1 to 4 'loop over the cross-sections
smpl @all if @crossid=!i and @obsid=2
series loop=@maxsby(JAN,!i, @obsid=2) - @maxsby(JAN,!i, "if @crossid=!i and @obsid=3") 'jan stands for january
next
It returns me the following error:
Error in Sample: !I is not defined in "SERIES
LOOP=@MAXSBY(JAN,1, @OBSID=2) - @MAXSBY(JAN,1, "IF
@CROSSID=!I AND @OBSID=3")".
How should I change the code that it would work properly?
I use EViews version 9.5.
Thank you!
Subtraction of panel data with loop
Moderators: EViews Gareth, EViews Moderator
-
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13319
- Joined: Tue Sep 16, 2008 5:38 pm
Re: Subtraction of panel data with loop
Without understanding why you're using @maxsby, it looks like you've missed off the @crossid part?
Code: Select all
@maxsby(JAN,!i, @obsid=2)
Code: Select all
@maxsby(JAN,@crossid=!i, @obsid=2)
Follow us on Twitter @IHSEViews
Re: Subtraction of panel data with loop
Thank you Gareth for the prompt reply.
Although I corrected the code as recommended:
for !i=1 to 4 'loop over the cross-sections
smpl @all if @crossid=!i and @obsid=2
series loop=@maxsby(JAN, @crossid=!i, @obsid=2) - @maxsby(JAN,@crossid=!i, "if @crossid=!i and @obsid=3") 'jan stands for january
next
I still get the error message:
Error in Sample: !I is not defined in "SERIES
LOOP=@MAXSBY(JAN, @CROSSID=1, @OBSID=2) -
@MAXSBY(JAN,@CROSSID=1, "IF @CROSSID=!I AND
@OBSID=3")".
Thank you!
Although I corrected the code as recommended:
for !i=1 to 4 'loop over the cross-sections
smpl @all if @crossid=!i and @obsid=2
series loop=@maxsby(JAN, @crossid=!i, @obsid=2) - @maxsby(JAN,@crossid=!i, "if @crossid=!i and @obsid=3") 'jan stands for january
next
I still get the error message:
Error in Sample: !I is not defined in "SERIES
LOOP=@MAXSBY(JAN, @CROSSID=1, @OBSID=2) -
@MAXSBY(JAN,@CROSSID=1, "IF @CROSSID=!I AND
@OBSID=3")".
Thank you!
-
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13319
- Joined: Tue Sep 16, 2008 5:38 pm
Re: Subtraction of panel data with loop
Code: Select all
%spec = "if @crossid=" + @str(!i) + " and @obsid=3"
series loop=@maxsby(JAN, @crossid=!i, @obsid=2) - @maxsby(JAN,@crossid=!i, %spec)
Follow us on Twitter @IHSEViews
Re: Subtraction of panel data with loop
The modified code
[for !i=1 to 4 'loop over the cross-sections
%spec = "if @crossid=" + @str(!i) + " and @obsid=3"
smpl @all if @crossid=!i and @obsid=2
series loop=@maxsby(JAN, @crossid=!i, @obsid=2) - @maxsby(JAN,@crossid=!i, %spec) 'jan stands for january
next]
returns only the result for the first crossid, while for the 2nd to 4th crossid it returns NA.
[for !i=1 to 4 'loop over the cross-sections
%spec = "if @crossid=" + @str(!i) + " and @obsid=3"
smpl @all if @crossid=!i and @obsid=2
series loop=@maxsby(JAN, @crossid=!i, @obsid=2) - @maxsby(JAN,@crossid=!i, %spec) 'jan stands for january
next]
returns only the result for the first crossid, while for the 2nd to 4th crossid it returns NA.
Re: Subtraction of panel data with loop
Gareth,
just a note that the modified code you proposed works!
Thank you so much for your help!
just a note that the modified code you proposed works!
Thank you so much for your help!
Return to “Suggestions and Requests”
Who is online
Users browsing this forum: No registered users and 32 guests