Unequal Variable Groups

For questions regarding programming in the EViews programming language.

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

Dreeken
Posts: 11
Joined: Tue May 14, 2013 12:28 am

Unequal Variable Groups

Postby Dreeken » Tue May 14, 2013 12:50 am

Dear EViews crew and other users,

I have a problem which I haven't seen around this forum as of yet, if any of you does know a thread containing a solution or discussion please let me know!
Anyways, my problem is as follows: I'm doing my master thesis with this company which wants to evaluate it's business units on an individual level (over 100 Business Units) based on costs, revenues and other variables. I have 8 variable groups now (each containing daily series since 01/01/2010 for each business unit). The problem is that certain business units do not posess certain activities and that as such the groups are not equal (some groups 'only' have 70 series instead of more than 100).

My programming knowledge is not very extensive, but I managed to write a bit of code which should go part of the way.

Code: Select all

matrix(6,132) coefs matrix(6,132) tstats vector(132) r2s matrix(2,132) archtest !rowcounter=1 equation eq for !i=1 to alfa.@count for !j=1 to beta.@count for !k=1 to gamma.@count for !l=1 to delta.@count for !m=1 to epsilon.@count for !n=1 to zeta.@count for !o=1 to eta.@count for !p=1 to theta.@count %iname=alfa.@seriesname(!i) %jname=beta.@seriesname(!j) %kname=gamma.@seriesname(!k) %lname=delta.@seriesname(!l) %mname=epsilon.@seriesname(!m) %nname=zeta.@seriesname(!n) %oname=eta.@seriesname(!o) %pname=theta.@seriesname(!p) equation eq_{%iname}.ls(n) {%iname} c {%jname} {%kname} {%lname} {%mname} {%nname} {%oname} {%pname} colplace(coefs, eq_{%iname}.@coefs, !i) colplace(tstats, eq_{%iname}.@tstats, !i) r2s(!rowcounter) = eq_{%iname}.@r2 eq_{%iname}.makeresids Res%iname freeze(archtable) eq_{%iname}.archtest(7) 'LM-ARCH Test on past 7 days archtest(!rowcounter, 1)=@val(archtable(3,2)) archtest(!rowcounter, 2)=@val(archtable(3,4)) d archtable !rowcounter=!rowcounter+1 next next next next next next next next
But how do I incorporate the fact that these groups are not equal? I need to make sure that all the variables match each other in each seperate equation. Can somebody please help me with this? I have a gut feeling that I could use an "if' function, but again I have no clue how I should implement that.

I'd really appreciate the help! And I'm using EViews 7 for this issue
Regards,
Dreeken

PS. I thought I'd might simply use empty series to equalize the groups (Filled with NA) only EViews will probably exclude every single observation due to this method, right?

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

Re: Unequal Variable Groups

Postby EViews Gareth » Tue May 14, 2013 7:58 am

You haven't really defined what the problem is. You have some groups that have a different number of series inside them... So what?

Dreeken
Posts: 11
Joined: Tue May 14, 2013 12:28 am

Re: Unequal Variable Groups

Postby Dreeken » Wed May 15, 2013 2:49 am

Hey Gareth,

Let me give a short example; suppose I have 3 Business Units (A, B, C). I have 6 variable groups, which all contain time series for each business unit. Except business unit 'B' only has 5 variables for, say, the first 5 groups. This means (I assume, anyway) that I will have the following regressions:

Code: Select all

Variable1A c Variable2A Variable3A Variable4A Variable5A Variable6A Variable1B c Variable2B Variable 3B Variable4B Variable5B Variable6C Variable1C c Variable2C Variable 3C Variable4C Variable5C
While I want each regression to only contain variables with respect to 1 specific business unit. Thus:

Code: Select all

Variable1A c Variable2A Variable3A Variable4A Variable5A Variable6A Variable1B c Variable2B Variable 3B Variable4B Variable5B Variable1C c Variable2C Variable 3C Variable4C Variable5C Variable6C
Was that a clear enough definition of my problem?

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

Re: Unequal Variable Groups

Postby EViews Gareth » Wed May 15, 2013 7:44 am

No?

Why does the size of the group matter when using the group in the equation specification?

Dreeken
Posts: 11
Joined: Tue May 14, 2013 12:28 am

Re: Unequal Variable Groups

Postby Dreeken » Tue May 21, 2013 6:50 am

To be honest, I'm not finished gathering the data yet (company IT issues) so I haven't gotten a chance to run my program as of yet. I'm just working ahead a bit now, so maybe I'm just a bit paranoid and it will all work fine when I run it :).

I do have another question, I've been looking for solutions for quite some days now but haven't really gotten one (neither from the forum, nor from the command ref. nor the object ref.). I want to use the coefficients that I've estimated and stored from the regressions in estimating the dependent variable for each day of the sample over which the regression was estimated. I then want to compare these estimates to the actual dependent variable on a percentage scale (using log(actual observation - estimated) should do that trick) and look at the discrepancies.

I did find something about declaring coefficients in the object reference so perhaps that's a good starting for this approach? Or is it also possible to re-use the coefficients that were already stored in the matrix? If so, I don't know how to call them forth from this table to use them again.

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

Re: Unequal Variable Groups

Postby EViews Gareth » Tue May 21, 2013 7:52 am

Not 100% clear on that either. You want the fitted values from the equation? That's just equation.fit.

You don't need the coefficients to build the fitted values, EViews will do it for you.

Dreeken
Posts: 11
Joined: Tue May 14, 2013 12:28 am

Re: Unequal Variable Groups

Postby Dreeken » Thu May 30, 2013 4:21 am

Hi Gareth,

Thanks for the suggestion using the fitted values; that works like a charm!

Anyways, I wondered if my program would work so I tried it on a generated datatset (I just generated some random number series for some of the variables) and made my program a bit smaller so that it would fit the generated dataset (see attached files). So then I tried to run my program but all kind of errors started popping up.

I have no idea what’s happening here. When I keep the rowcounter line within the loops, it keeps giving an error:

4 is not a valid index for vector-series-coefficient r2s in “R2S(4)=EQ_ALFA_TS1.@R2”.

Which is odd to say the least, since the program (for as far as I can see) shouldn’t even return ‘4’ for EQ_ALFA_TS1 or any other equation for that matter. What is happening with that line?

When I decide to take the rowcounter to the outside of the loop to try and fix the above mentioned problem another issue occurs. Only the dependent variable (the Alfa Group for this occasion) changes with each loop but the independent variables remain BETA_TS3 and GAMMA_TS3. But I want the variables to match each other (So all TS1 variables in one equation and the same for all TS2 and TS3 variables). So changing the location of the rowcounter line isn’t a solution either. What can I do about this problem?

If I'm still being not particularly clear on some things, please let me know and I'll try to explain..
Attachments
TESTFILE.WF1
(101.98 KiB) Downloaded 305 times
Program rowcounter inside.txt
The rowcounter line is inside the loops in this program
(694 Bytes) Downloaded 342 times
program rowcounter outside.txt
The rowcounter line is outside the loops in this program
(658 Bytes) Downloaded 606 times

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

Re: Unequal Variable Groups

Postby EViews Gareth » Thu May 30, 2013 7:20 am

Your three loops are nested. That means you're running 3x3x3 iterations of the inner loop. Thus you're performing 27 regressions. So rowcounter will equal 4 (and 5, and 6, and 7, and....27).

Dreeken
Posts: 11
Joined: Tue May 14, 2013 12:28 am

Re: Unequal Variable Groups

Postby Dreeken » Mon Jun 03, 2013 4:33 am

Thanks for the response Gareth :) Now that you've said it, seeing the problem is actually quite simple.
Alas, my programming knowledge is really small and now I'm having trouble to create a single loop in such a way that I only get the 3 equations that I want. I've tried putting them in as string variables and as control variables (as described in the programming reference) but I keep on getting syntax errors. So I'm clearly doing something wrong.

Can you give me the correct programming line or a reference to where I can find that line?

PS. Sorry for all of my easy/stupid questions I've posted here, I just don't know how to get an answer in any other way..

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

Re: Unequal Variable Groups

Postby EViews Gareth » Mon Jun 03, 2013 6:36 am

Post your latest attempt.

Dreeken
Posts: 11
Joined: Tue May 14, 2013 12:28 am

Re: Unequal Variable Groups

Postby Dreeken » Mon Jun 03, 2013 10:14 am

Hey Gareth,
I thought up of something else; if I simply (duh.) define the number of iterations of the loop and let every group change with a step size of 1 with each iteration I should hit gold, right?
Well, no. If I do this (see attached files) the issue that originally lead to this thread pops up. You can see that when you look at the second equation (eq_alfa_ts2) which has beta_ts_2 and gamma_ts_3 as independent variables.
So, how to solve this?

PS. I guess I could always try to split up business units into multiple groups (for example: a group of BUs for which every variable exists, a group of BUs which miss one of the variables, etc. etc.). But I'd prefer to run a single program..
Attachments
Program rowcounter inside v2.txt
(623 Bytes) Downloaded 636 times
testfile.wf1
(107.47 KiB) Downloaded 281 times

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

Re: Unequal Variable Groups

Postby EViews Gareth » Mon Jun 03, 2013 10:17 am

In that workfile, your Gamma group only has two series in it. There does not appear to be a series gamma_ts2 series.

Dreeken
Posts: 11
Joined: Tue May 14, 2013 12:28 am

Re: Unequal Variable Groups

Postby Dreeken » Mon Jun 03, 2013 10:35 am

Which was exactly my point. Since some of the business units do not have certain activities, they miss the variable specific to that activity and therefore the groups have unequal sizes.
I already said this a few posts back, but maybe I was a bit fuzzy in explaining it.
Let me give a short example; suppose I have 3 Business Units (A, B, C). I have 6 variable groups, which all contain time series for each business unit. Except business unit 'B' only has 5 variables for, say, the first 5 groups. This means (I assume, anyway) that I will have the following regressions:

Code: Select all
Variable1A c Variable2A Variable3A Variable4A Variable5A Variable6A

Variable1B c Variable2B Variable 3B Variable4B Variable5B Variable6C

Variable1C c Variable2C Variable 3C Variable4C Variable5C



While I want each regression to only contain variables with respect to 1 specific business unit. Thus:

Code: Select all
Variable1A c Variable2A Variable3A Variable4A Variable5A Variable6A

Variable1B c Variable2B Variable 3B Variable4B Variable5B

Variable1C c Variable2C Variable 3C Variable4C Variable5C Variable6C



Was that a clear enough definition of my problem?
As I look at it now, the easiest way to solve it is to make separated workfiles for groups of Business units who have the same amount of variables. Or is there another way?

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

Re: Unequal Variable Groups

Postby EViews Gareth » Mon Jun 03, 2013 10:41 am

You're probably grouping in the wrong direction then.

How about something like:

Code: Select all

group ts1 *ts1 group ts2 *ts2 group ts3 *ts3 for !i=1 to 3 equation eq_alfa_ts{!i}.ls ts{!i} c next

Dreeken
Posts: 11
Joined: Tue May 14, 2013 12:28 am

Re: Unequal Variable Groups

Postby Dreeken » Mon Jun 03, 2013 10:49 am

Thanks Gareth! That should serve my purposes for as far as I can see now!

You're the best :)


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 1 guest