Page 1 of 1

Extracting a name from a string vector

Posted: Mon Mar 20, 2017 9:50 am
by Marc150
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

Re: Extracting a name from a string vector

Posted: Mon Mar 20, 2017 10:22 am
by EViews Gareth
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