If statement within a loop for panel data

For questions regarding programming in the EViews programming language.

Moderators: EViews Gareth, EViews Jason, EViews Moderator, EViews Matt

sky22
Posts: 2
Joined: Wed Mar 03, 2021 1:36 pm

If statement within a loop for panel data

Postby sky22 » Wed Mar 03, 2021 1:47 pm

I need advice on a simple program I am trying to run which does not work. I want to include an IF statement within a loop. The data is a panel series in long form, so variable year is a repeated series

SERIES INF
For !YR=1990 to 2017
If year =!yr then
GENR inf=f{!yr}cpi
endif
next

The series inf remains blank. How do i fix this?
thank you
Last edited by sky22 on Wed Mar 03, 2021 2:09 pm, edited 2 times in total.

startz
Non-normality and collinearity are NOT problems!
Posts: 3775
Joined: Wed Sep 17, 2008 2:25 pm

Re: If statement within a loop

Postby startz » Wed Mar 03, 2021 1:59 pm

Try

Code: Select all

smpl if year = !yr
inf=f{!yr}cpi
smpl @all

sky22
Posts: 2
Joined: Wed Mar 03, 2021 1:36 pm

Re: If statement within a loop

Postby sky22 » Wed Mar 03, 2021 2:07 pm

Hi
thank you but the smpl function does not work as the data is a panel. so the sample is country and time. I have a separate variable for year and country.
Is there a way around this?

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

Re: If statement within a loop for panel data

Postby EViews Matt » Fri Mar 05, 2021 2:40 pm

Hello,

If you're saying that variable "year" is a series, then the "year = !yr" expression is not meaningful as part of an if statement conditional. Can you describe what you're trying to accomplish with your code?


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 21 guests