Page 1 of 1

Loops using strings and scalars at the same time

Posted: Mon Sep 23, 2013 2:23 am
by ectrie
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!!!!

Re: Loops using strings and scalars at the same time

Posted: Mon Sep 23, 2013 3:04 am
by ectrie
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?

Re: Loops using strings and scalars at the same time

Posted: Mon Sep 23, 2013 7:54 am
by EViews Gareth
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

Re: Loops using strings and scalars at the same time

Posted: Tue Sep 24, 2013 4:54 am
by ectrie
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!

Re: Loops using strings and scalars at the same time

Posted: Tue Sep 24, 2013 6:37 am
by EViews Gareth
Group section of the Object Reference