Illogical syntax?
Posted: Fri Jul 30, 2010 9:41 am
Hello there,
I'm trying to understand the syntax of EViews (7), but sometimes it just doesn't make sense. Two problems.
1. First:
Let's say I have returns for 100 companies (!firm). Each of the company is categorized into a symbol from 1 to 10 (!industry). Since the first column in all 100 series is empty, I used that space to have the industry code (from 1 to 10).
I expected from the above code that it would create 10 variables (!no_1, !no_2, etc.), and at the end of the main loop, each of those variable will contain a number of firms having the specific industry code. But that doesn't work, and at the end of the loop, all of those variables have value of 100 (equal to a number of firms). That doesn't make sense, as there's a FOR statement, which increases a particular variable only if the first row fulfills the specific condition. For example, the statement
should increase the variable !no_1 only if the first row is equal to 1. If found the solution by adding the following code (marked by the exclamation marks), which I don't really like (it makes the code messy), but I'm more interested why the first code doesn't work? The FOR statement is correct, since it works for a series, but it doesn't work for a variable. Why?
2. Second
Now I want to reorganize the series by the industry code. For example, if firm 21, 72 and 98 have the same code (say 1), I want to create a new series: industry_1_1, industry_1_2, industry_1_3 containing values of d21, d72, and d98, respectively. So I add the following code (again, the new code is marked by the exclamation marks):
My logic was following. In the main loop (i.e. from 1 to 10), a new variable is created with the value of 1. Then, if, for example, the first row in d54 is equal to 1, then a new series is creates with a name of industry_1_1. The variable is then updates and takes value of 2. So, if then the first row in d79 equals 1, another series is created: industry_1_2, and again the variable is updated and takes a value of 3. When all firms with the first value of 1 are gone, the main loop looks then at the firms having the first row of 2. Before than, the variable (!count) is updated to have a value of 1 again.
The result of the program is that it creates series: industry_1_1 to industry_1_100, industry_2_1 to industry_2_100, industry_3_1 to industry_3_100, etc. The series industry_1_1, industry_2_1, industry_3_1, etc. are the same.
Why does it not work?
I'm trying to understand the syntax of EViews (7), but sometimes it just doesn't make sense. Two problems.
1. First:
Code: Select all
for !industry=1 to 10
!no_{!industry} = 0
for !firm=1 to 100
smpl 1/1/2010 1/1/2010 if d{!firm} = {!industry}
!no_{!industry} = !no_{!industry} + 1
smpl @all
next
next
I expected from the above code that it would create 10 variables (!no_1, !no_2, etc.), and at the end of the main loop, each of those variable will contain a number of firms having the specific industry code. But that doesn't work, and at the end of the loop, all of those variables have value of 100 (equal to a number of firms). That doesn't make sense, as there's a FOR statement, which increases a particular variable only if the first row fulfills the specific condition. For example, the statement
Code: Select all
smpl 1/1/2010 1/1/2010 if d{!firm} = 1
!no_1 = !no_1 + 1
smpl @all
Code: Select all
for !industry=1 to 10
!! smpl 1/1/2010 1/1/2010
!! series no_{!industry}
!! smpl @all
for !firm=1 to 100
smpl 1/1/2010 1/1/2010 if d{!firm} = {!industry}
!! series no_{!industry} = no_{!industry} + 1
smpl @all
next
!! !no_{!industry} = @mean(no_{!industry})
!! delete no_{!industry}
next
Now I want to reorganize the series by the industry code. For example, if firm 21, 72 and 98 have the same code (say 1), I want to create a new series: industry_1_1, industry_1_2, industry_1_3 containing values of d21, d72, and d98, respectively. So I add the following code (again, the new code is marked by the exclamation marks):
Code: Select all
for !industry=1 to 10
smpl 1/1/2010 1/1/2010
series no_{!industry}
smpl @all
for !firm=1 to 100
smpl 1/1/2010 1/1/2010 if d{!firm} = {!industry}
series no_{!industry} = no_{!industry} + 1
smpl @all
next
!no_{industry} = @mean(no_{!industry})
delete no_{!industry}
!! !count = 1
!! for !firm=1 to 100
!! smpl 1/1/2010 1/1/2010 if d{!firm} = {!industry}
!! series industry_{!industry}_{!count} = d{!firm}
!! !count = !count + 1
!! smpl @all
!! next
next
The result of the program is that it creates series: industry_1_1 to industry_1_100, industry_2_1 to industry_2_100, industry_3_1 to industry_3_100, etc. The series industry_1_1, industry_2_1, industry_3_1, etc. are the same.
Why does it not work?