Converting a string into a formula

For questions regarding programming in the EViews programming language.

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

rf2009
Posts: 4
Joined: Mon Mar 16, 2009 6:25 am

Converting a string into a formula

Postby rf2009 » Mon Mar 16, 2009 7:03 am

Dear All,

I would like to know how I can convert a string into a formula (I guess this is how you would call it in Excel). I have a table with formulas in separate cells (for example in one cell I have 4+2*2) and now I want to have the outcome of the formulas in other cells (so in the former example 8).

So if you do the following, you get what I have now (I cannot think of a way that avoids getting the formulas as a string in a table):

Code: Select all

table tab01 %x="4+2*2" tab01(1,1)=%x
Now I want cell (1,2) to give the outcome of the formula (so 8). I would initially think of something like this:

Code: Select all

!y=tab01(1,1) '(This is of course not possible: “string assigned to scalar”) scalar z=!y tab01(1,2)=z
Since this is not possible, the question is: how to convert the string (formula) into a scalar (outcome of the formula)?

Some things that did not work:
1) @val option: it does not recognize the calculation symbols like +, -, etc.
2) tab01(1,2)="="+tab01(1,1). This does not convert the string into a value (although if you open the table, press edit and click on the cell it changes from “=4+2*2” into “8”. But this is not practical, since I have thousands of different formulas).

Any help is much appreciated!

EViews Glenn
EViews Developer
Posts: 2682
Joined: Wed Oct 15, 2008 9:17 am

Re: Converting a string into a formula

Postby EViews Glenn » Mon Mar 16, 2009 9:37 am

I have a question about what it actually is that you want to do that I'll address in a minute. Having said that, what you can do is to bounce the string in your table off of a series, and then grab the string value back.

smpl @first @first
%z = table01(1,1)
frml temp = {%z}
tabl01(1,2)=@str(@min(f3))

This is doing an awful lot of work just to evaluate the string to get a number. EViews really isn't, at present built to do the kind of spreadsheet evaluation that Excel does; in particular, i's designed to work with series rather than scalars. That said, if all you want to do is to do scalar evaluations of this type, you can get it to work using frmls and programs as described above, but it's a bit like using a chainsaw instead of an pairing knife.

What exactly are you trying to do with your table?

rf2009
Posts: 4
Joined: Mon Mar 16, 2009 6:25 am

Re: Converting a string into a formula

Postby rf2009 » Tue Mar 17, 2009 1:46 am

Dear Glenn,

Thank you for your help. It works perfectly!

About the goal of the table:
I have a long expression of which I want to know the value. This expression depends on many other long expressions which again depend on estimated parameters (both the value and the form of the expressions depend on the parameters). I generated the form of these latter expressions as strings and stored them in a table. Now I am planning to insert the estimated coefficients into these expressions via the usual string options. Next, I want to calculate the value of the expressions (my question) and use them for calculating the first expression.


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests