Extracting a name from a string vector

For questions regarding programming in the EViews programming language.

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

Marc150
Posts: 10
Joined: Fri Mar 17, 2017 10:50 am

Extracting a name from a string vector

Postby Marc150 » Mon Mar 20, 2017 9:50 am

Hi,

I would like to conditionally assign names to observations under a name variable in a cross-section dataset. I have created a string vector to store the names. Then, I have tried to use a for loop to name the observations, according to the crossid values. However, EViews does not seem to recognize the elements of the string vector as characters, and so returns an error. I have also tried putting quotation marks around prov_names(i), however, this just returns "prov_names(I)", which it now views as a character, i.e., it does not identify !i and cycle through the for loop. Here is my code:

wfcreate(wf=annual) a 1981 2015 10
alpha province
svector(10) prov_names
prov_names(1)="Newfoundland and Labrador"
prov_names(2)="Prince Edward Island"
prov_names(3)="Nova Scotia"
prov_names(4)="New Brunswick"
prov_names(5)="Quebec"
prov_names(6)="Ontario"
prov_names(7)="Manitoba"
prov_names(8)="Saskatchewan"
prov_names(9)="Alberta"
prov_names(10)="British Columbia"
for !i=1 to 10
smpl if crossid=!i
province=prov_names(!i)
next

Thank you in advance,
Marc

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13583
Joined: Tue Sep 16, 2008 5:38 pm

Re: Extracting a name from a string vector

Postby EViews Gareth » Mon Mar 20, 2017 10:22 am

Yeah, you'll have to go through an intermediate.

Code: Select all

for !i=1 to 10 smpl if crossid=!i %temp = prov_names(!i) province=%temp next


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests