Problem with strings and variables

For questions regarding programming in the EViews programming language.

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

sean123
Posts: 34
Joined: Wed Apr 25, 2012 11:53 am

Problem with strings and variables

Postby sean123 » Mon Jun 23, 2014 12:22 am

Hi!

I have a program which is based on a prompt where the user provides a number of inputs. I'm now extending it and having some problems with one part. The program is for forecasting purposes, and what I would like to have is the user provide a list of variables and a sample for which these variables are to be conditioned on. In EViews terms, this means that the user supplies a string with variables and one with a sample which are then to be added to the "exclude" option of a model object. However, my problem is I'm not getting the string versus variable thing right. Here is some example code:

Code: Select all

' User-supplied start and end: %smpl = "2006q1 2006q1" 'User-supplied variable to exlude: %variable = "x y" ' Create workfile, series and ' VAR and model objects create wf q 1960q1 2010q4 series x = nrnd series y = nrnd series z = nrnd smpl 1960q1 2005q4 var var.ls 1 2 x y z var.makemodel(model) smpl 2006q1 2010q4 ' String containing variable ' to condition on with the ' provided sample string exclude = @wcross(%variable, "(" + %smpl + ")") model.exclude {exclude}
The idea is that the user supplies the sample and variable in %smpl and %variable. In this example, I want to solve the model over the forecasting sample (2006q1 through 2010q4) with 2006q1 excluded for the variables x and y. My problem is that what this yields is basically the same as if I were to write:

Code: Select all

model.exclude "x(2006q1 2006q1)" "y(2006q1 2006q1)"
instead of what I want:

Code: Select all

model.exclude x("2006q1 2006q1") y("2006q1 2006q1")
Can anyone help me with this seemingly easy issue? Not sure how to deal with this string problem. Thanks!

sean123
Posts: 34
Joined: Wed Apr 25, 2012 11:53 am

Re: Problem with strings and variables

Postby sean123 » Mon Jun 23, 2014 1:34 am

I think I got it now. The last part of the example code is replaced by

Code: Select all

string exclude for !i=1 to @wcount(%variable) %temp = @word(%variable, !i) + "(" + @addquotes(%smpl) + ")" exclude = @wunion(exclude, %temp) next model.exclude {exclude}
which seems to work the way I want it to.


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests