Loops using strings and scalars at the same time

For questions regarding programming in the EViews programming language.

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

ectrie
Posts: 9
Joined: Mon Sep 09, 2013 10:24 am

Loops using strings and scalars at the same time

Postby ectrie » Mon Sep 23, 2013 2:23 am

Hello!

I want to make a loop that incorporates both strings and integers. So far I have created a group with a lot of variables (+/- 200). I'm working on a project where p > n, that means I have more variables then observations. There is a method called the LASSO method that chooses some of the variables from the group that are 'relevant' and gives the one that are not relevant a coefficient of zero. I have a serie called "serie_test" with the indexes of the group that I want to regress on the dependant variable. For example: I want to regress the variables 3,4 and 12 on the dependant variables. In EViews it will look like this:

Code: Select all

equation regression.ls y group01(3) group01(4) group01(12)
I made a loop for this looking like this:

Code: Select all

string test = "" !numberOfRows = @rows(serie_test) for !i = 1 to !numberOfRows test = test + "group01(serie_test(!i))" next
However, my output looks like this:
group01(serie_test(!i)) group01(serie_est(!i)) group01(serie_test(!i))
In stead of group01(serie_test(!i)) I want my output to be like this: group01(3) group01(4) etc.

Can someone help me please?

Thanks in advance!!!!

ectrie
Posts: 9
Joined: Mon Sep 09, 2013 10:24 am

Re: Loops using strings and scalars at the same time

Postby ectrie » Mon Sep 23, 2013 3:04 am

By the way, assuming the code will eventually work, the string will look something like this:

Code: Select all

string testString = "group01(3) group01(4) group(12)"
Now, if I want to regress on these variables I can't state:

Code: Select all

equation testRegression.ls y testString
It will produce an error that testString is not a serie. How can I solve for this?

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

Re: Loops using strings and scalars at the same time

Postby EViews Gareth » Mon Sep 23, 2013 7:54 am

Better off doing something like:

Code: Select all

group regsgroup !numberOfRows = @rows(serie_test) for !i = 1 to !numberOfRows regsgroup.add group01(!i) next equation regression.ls y regsgroup

ectrie
Posts: 9
Joined: Mon Sep 09, 2013 10:24 am

Re: Loops using strings and scalars at the same time

Postby ectrie » Tue Sep 24, 2013 4:54 am

Thanks for the help! On which page of the help documentation can I find more information about the .add functionality? I was trying to look it up but could not find it. Thanks in advance!

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

Re: Loops using strings and scalars at the same time

Postby EViews Gareth » Tue Sep 24, 2013 6:37 am

Group section of the Object Reference


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests